This file is indexed.

/usr/share/emacs/site-lisp/acl2/mfm.el is in acl2-emacs 4.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
;; May, 1994 [modified Oct., 1997]
;; Matt Kaufmann and Mike Smith

;; This file lets one attach a filter and a collection of buffers to a
;; process in emacs.  See mfm-acl2.el for an example of how to use the
;; utilities in this file.  It should work in emacs version 18, emacs version
;; 19 with comint, and version 19 with an old-style shell (Bill Schelter's
;; sshell.el).

;; If using this with buffers that use comint for processes, it's a good idea
;; to (setq mfm-comint-p t) in one's .emacs file.  Otherwise, this file uses
;; comint (i.e., mfm-comint-p is t) if and only if the emacs version is 19 or
;; later and Schelter's sshell is not present as a feature.

;; Possible future extensions:

; Consider saving the buffer's process filter before installing our
; own, and restoring it when executing stop-proof-tree.  This is also
; important to do when we change the *mfm-buffer*.

; Think about the effect of renaming a shell buffer.

; Create a way for #<\<e ... #>\> to cause the form to be read into
; emacs and evaluated.

(defvar mfm-emacs-version
  (if (and (boundp 'emacs-version)
           (stringp emacs-version)
           (< 1 (length emacs-version))
           (string-match "[0-9][0-9]" (substring emacs-version 0 2)))
      (string-to-int (substring emacs-version 0 2))
    (error "The file mfm.el works for emacs versions 18 and 19, but not yours.")))

(defvar mfm-comint-p
  (and (<= 19 mfm-emacs-version)
       (not (featurep 'sshell))))

; For the byte compiler:

(defvar last-input-end)
(defvar comint-last-input-end)
(defvar comint-output-filter-functions)
(defvar comint-last-output-start)

(defun mfm-update-last-input-end (nchars)
  (let ((end (if mfm-comint-p 
                 comint-last-input-end
               last-input-end)))
    (if (and end
             (marker-buffer end)
             (= (point) end))
        (set-marker end (- end nchars)))))

(defun mfm-update-last-output-start (ostart)
  (if mfm-comint-p
      (set-marker comint-last-output-start ostart)
    nil))

(defun mfm-force-mode-line-update ()
  (if mfm-comint-p
      (force-mode-line-update)
    nil))

; e.g., "*shell*"
(defvar *mfm-buffer* nil)

; The following is adapted from a contribution from Noah Friedman, from his
; ftelet mode.
(defun ftelnet-carriage-filter (string)
  (let* ((point-marker (point-marker))
         (proc (get-buffer-process (current-buffer)))
         (end (if proc (process-mark proc) (point-max)))
         (beg (or (and proc
                       (boundp 'comint-last-output-start)
                       comint-last-output-start)
                  (- end (length string)))))
    (goto-char beg)
    (while (search-forward "\C-m" end t)
      (delete-char -1))
    (goto-char point-marker)))

(defvar *mfm-secondary-filter-functions* '(ftelnet-carriage-filter))

(defvar *mfm-secondary-buffer* nil
  "This variable is NIL if we are not currently accumulating output
to the secondary buffer.  If we are its value is that buffer.")

(defvar *mfm-secondary-buffer-name-alist* nil)

; We were relying on the rarity of the breaking up of a string #<\<0 or
; #>\>  So far so good, said the guy falling past the 82nd floor....
; Broke.  So we are fixing it.

(defvar *mfm-protocol-start* "#"
  "Character used to start and stop redirection.")

(defun mfm-initial-secondary-start ()
  (format "#<[\\]<[%s]" 
          (apply 'concat
                 (mapcar 'char-to-string
                         (mapcar 'car
                                 (mapcar 'cdr
                                         *mfm-secondary-buffer-name-alist*))))))

(defvar *mfm-secondary-start*
  (mfm-initial-secondary-start))

(defvar *mfm-secondary-stop* "#>[\\]>")

; The value of *mfm-secondary-stop-len* should be the length of any string that
; matches *mfm-secondary-stop*.
(defvar *mfm-secondary-stop-len* 4)

(defvar *mfm-paused-buffers* nil)

(defvar *mfm-secondary-buffer-alist* nil)

(defun mfm-output-filter-functions ()
  (if mfm-comint-p
      (delete t comint-output-filter-functions)
    nil))

(defun mfm-paused-buffers (alist)
  (if (null alist)
      nil
    (if (memq 'pause (cdr (cdr (car alist))))
        (cons (car (car alist))
              (mfm-paused-buffers (cdr alist)))
      (mfm-paused-buffers (cdr alist)))))

(defun mfm-create-buffers-from-secondary-buffer-name-alist ()
  ;; This is OK even if some or all of the buffers already exist.
  (setq *mfm-secondary-buffer-alist*
	(mapcar (function (lambda (pair)
			    (cons (car (cdr pair))
				  (get-buffer-create (car pair)))))
		*mfm-secondary-buffer-name-alist*)))

(defun mfm-initialize-secondary-buffer-alist ()
  (mfm-create-buffers-from-secondary-buffer-name-alist)
  (setq *mfm-paused-buffers*
        (mfm-paused-buffers *mfm-secondary-buffer-name-alist*))
  (setq *mfm-secondary-start*
        (mfm-initial-secondary-start)))

(defvar *mfm-saved-tail* "")
(defvar *mfm-secondary-text* "")

(defun mfm-string-start (string)
  ;; Return nil or pair.
  ;; If pair = (n NIL), then we have a match for *mfm-secondary-start* at n.
  ;; If pair = (n T),   then we have a match for *mfm-protocol-start* at n, and
  ;;  n indexs one of the last four characters of string.
  (let ((start (string-match *mfm-secondary-start* string)))
    (cond (start (list start nil))
	  ((string-match *mfm-protocol-start* string (max (- (length string) 4) 0))
	   (list (match-beginning 0) t))
	  (t nil))))

(defun mfm-string-stop (string)
  ;; Return nil or pair.
  ;; If pair = (n NIL), then we have a match for *mfm-secondary-stop* at n;
  ;; elseif pair = (n T), then we have a match for *mfm-protocol-start* at n,
  ;; and n indexes one of the last four characters of string.
  (let ((stop (string-match *mfm-secondary-stop* string)))
    (cond (stop (list stop nil))
	  ((string-match *mfm-protocol-start*
                         string
                         (max (- (length string) 3) 0))
	   (list (match-beginning 0) t))
	  (t nil))))

(defun mfm-output-filter (process string)
  ;; At this point we need to check if secondary start or stop
  ;; is contained in string.
  ;; Previously error prone in case of xxx START xx START xx STOP xx STOP xx...
  ;; Modified to handle start and stop broken across successive strings.
  ;; E.g., xxxSTA RTxxxx xxxxST OPxxx
  (setq string (concat *mfm-saved-tail* string))
  (setq *mfm-saved-tail* "")
  (if *mfm-secondary-buffer*
      ;; We are currently writing to one of the secondary buffers.
      (let ((stop (mfm-string-stop string)))
	(cond ((null stop)
	       (setq *mfm-secondary-text*
		       (concat *mfm-secondary-text* string)))
	      ((null (car (cdr stop)))
	       (setq stop (car stop))
               ;; Write the accumulated text, including the appropriate part of
               ;; STRING.  First write the current point as the first line.
	       (mfm-output-to-secondary
                *mfm-secondary-buffer*
                (concat *mfm-secondary-text*
                        (substring string 0 stop)))
               (setq *mfm-secondary-buffer* nil)
	       (setq *mfm-secondary-text* "")
	       (mfm-output-filter
		process
		(substring string (+ stop *mfm-secondary-stop-len*))))
	      ((car (cdr stop))
	       (setq stop (car stop))
	       ;; May or may not be done.
	       ;; Add the accumulated text to *mfm-secondary-text*.
	       (setq *mfm-secondary-text*
		       (concat *mfm-secondary-text* (substring string 0 stop)))
	       (setq *mfm-saved-tail* (substring string stop)))))

    (let* ((start (mfm-string-start string))
           (end (and start (match-end 0))))
      (cond ((null start) (mfm-output-to-primary process string))
            ((null (car (cdr start)))
	     (setq start (car start))
             ;; Write the appropriate part of STRING to primary output
             ;; Then enter secondary buffer mode.
             (mfm-output-to-primary process
                                    (substring string 0 start))
             (setq *mfm-secondary-buffer*
                   (cdr (assq (aref string (1- end))
                              *mfm-secondary-buffer-alist*)))
             (if (null (buffer-name *mfm-secondary-buffer*))
                 (progn (mfm-create-buffers-from-secondary-buffer-name-alist)
                        (setq *mfm-secondary-buffer*
                              (cdr (assq (aref string (1- end))
                                         *mfm-secondary-buffer-alist*)))))
             (mfm-output-filter process (substring string end)))
	    ((car (cdr start))
	     (setq start (car start))
	     (mfm-output-to-primary process (substring string 0 start))
	     (setq *mfm-saved-tail* (substring string start)))))))

(defun mfm-output-to-primary (process string)
  ;; First check for killed buffer
  (let ((oprocbuf (process-buffer process)))
    (if (and oprocbuf (buffer-name oprocbuf))
        (let ((obuf (current-buffer))
              (opoint nil) (obeg nil) (oend nil))
          (set-buffer oprocbuf)
          (setq opoint (point))
          (setq obeg (point-min))
          (setq oend (point-max))
          (let ((buffer-read-only nil)
                (nchars (length string))
                (ostart nil))
            (widen)
            (goto-char (process-mark process))
            (setq ostart (point))
            (if (<= (point) opoint)
                (setq opoint (+ opoint nchars)))
            ;; Insert after old_begv, but before old_zv.
            (if (< (point) obeg)
                (setq obeg (+ obeg nchars)))
            (if (<= (point) oend)
                (setq oend (+ oend nchars)))
            (insert-before-markers string)
            ;; Don't insert initial prompt outside the top of the window.
            (if (= (window-start (selected-window)) (point))
                (set-window-start (selected-window) (- (point) (length string))))
            (mfm-update-last-input-end nchars)
            (mfm-update-last-output-start ostart)
            (set-marker (process-mark process) (point))
            (mfm-force-mode-line-update))

          (narrow-to-region obeg oend)
          (goto-char opoint)
          (ftelnet-carriage-filter string)
          (let ((functions (mfm-output-filter-functions)))
            (while functions
              (funcall (car functions) string)
              (setq functions (cdr functions))))
          (set-buffer obuf)))))

(defun member-equal (a lst)
  ;; because member is not defined in version 18
  (if (null lst)
      nil
    (if (equal a (car lst))
        lst
      (member-equal a (cdr lst)))))

(defun mfm-paused-p (buffer-name)
  (member-equal buffer-name *mfm-paused-buffers*))

(defun mfm-output-to-secondary (oprocbuf string)
  ;; First check that buffer exists.
  (if (and oprocbuf (buffer-name oprocbuf))
      (let ((obuf (current-buffer)))
        (if ; Stop output to "pause" buffers.
            (mfm-paused-p (buffer-name oprocbuf))
            nil
          (set-buffer oprocbuf)
          ;; Clear buffer before displaying string.
          (delete-region (point-min) (point-max))
          (let ((buffer-read-only nil))
            (insert string))
          (mfm-force-mode-line-update)
          (let ((functions *mfm-secondary-filter-functions*))
            (while functions
              (funcall (car functions) string)
              (setq functions (cdr functions))))
          (set-buffer obuf)))))

(defun mfm-abort-secondary-buffer ()

  "Flush the text currently being sent to the secondary buffer and
resume sending text to primary buffer.  This does not stop or pause
the sending of output to secondary buffers; it merely flushes the
current stream being sent to a secondary buffer (if any)."

  (interactive)
  (setq *mfm-secondary-buffer* nil)
  (setq *mfm-saved-tail* "")
  (setq *mfm-secondary-text* ""))

(defun mfm-interrupt-subjob ()
  (interactive)
  (progn
    (mfm-abort-secondary-buffer)
    ;; use funcall here to avoid confusing the compiler
    (if mfm-comint-p
        (if (eq major-mode 'telnet-mode)
            (funcall 'telnet-interrupt-subjob)
          (funcall 'comint-interrupt-subjob))
      (funcall 'interrupt-shell-subjob))))

(defun mfm-set-keymap-interrupt ()
  (save-excursion
    (if *mfm-buffer*
        (progn (set-buffer *mfm-buffer*)
               (define-key (current-local-map)
                 "\C-C\C-C"
                 'mfm-interrupt-subjob)))))

(defun mfm-select-buffer-window (buffer)

  "Select a window containing the given buffer if there is one; otherwise, make
the current window fill the frame, and select the indicated buffer."
  (let ((w (get-buffer-window buffer)))
    (if w
        (select-window w)
      (progn (delete-other-windows)
             (switch-to-buffer buffer)))))

(provide 'mfm)