comparison lisp/list-mode.el @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents 74fd4e045ea6
children 697ef44129c6
comparison
equal deleted inserted replaced
403:9f011ab08d48 404:2f8bb876ab1d
1 ;;; list-mode.el --- Major mode for buffers containing lists of items 1 ;;; list-mode.el --- Major mode for buffers containing lists of items
2 2
3 ;; Copyright (C) 1992-4, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992-4, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1996 Ben Wing. 4 ;; Copyright (C) 1996, 2000 Ben Wing.
5 5
6 ;; Maintainer: XEmacs Development Team 6 ;; Maintainer: XEmacs Development Team
7 ;; Keywords: extensions, dumped 7 ;; Keywords: extensions, dumped
8 8
9 ;; This file is part of XEmacs. 9 ;; This file is part of XEmacs.
61 (dolist (key '(kp-right right (control ?f))) 61 (dolist (key '(kp-right right (control ?f)))
62 (define-key map key 'next-list-mode-item)) 62 (define-key map key 'next-list-mode-item))
63 (dolist (key '(kp-left left (control ?b))) 63 (dolist (key '(kp-left left (control ?b)))
64 (define-key map key 'previous-list-mode-item)))) 64 (define-key map key 'previous-list-mode-item))))
65 65
66 ;; #### We make list-mode-hook, as well as completion-setup-hook and
67 ;; minibuffer-setup-hook, permanent-local so that it's possible to create
68 ;; buffers in these modes and then set up some buffer-specific
69 ;; customizations without resorting to awful kludges. (The problem here
70 ;; is that when you switch a buffer into a mode, reset-buffer is usually
71 ;; called, which destroys all buffer-local settings that you carefully
72 ;; tried to set up when you created the buffer. Therefore, the only way
73 ;; to set these variables is to use the setup hooks -- but if they are
74 ;; not declared permanent local, then any local hook functions that you
75 ;; put on them (which is exactly what you want to do) also get removed,
76 ;; so you would have to resort to putting a global hook function on the
77 ;; setup hook, and then making sure it gets removed later. I actually
78 ;; added some support for doing this with one-shot hooks, but this is
79 ;; clearly not the correct way to do things, and it fails in some cases,
80 ;; particularly when the buffer gets put into the mode more than once,
81 ;; which typically happens with completion buffers, for example.) In
82 ;; fact, all setup hooks should be made permanent local, but I didn't
83 ;; feel like making a global change like this quite yet. The proper way
84 ;; to do it would be to declare new def-style forms, such as defhook and
85 ;; define-local-setup-hook, which are used to initialize hooks in place
86 ;; of the current generic defvars. --ben
87
88 (put 'list-mode-hook 'permanent-local t)
89 (defvar list-mode-hook nil
90 "Normal hook run when entering List mode.")
91
66 (defun list-mode () 92 (defun list-mode ()
67 "Major mode for buffer containing lists of items." 93 "Major mode for buffer containing lists of items."
68 (interactive) 94 (interactive)
69 (kill-all-local-variables) 95 (kill-all-local-variables)
70 (use-local-map list-mode-map) 96 (use-local-map list-mode-map)
71 (setq mode-name "List") 97 (setq mode-name "List")
72 (setq major-mode 'list-mode) 98 (setq major-mode 'list-mode)
73 (make-local-hook 'post-command-hook) 99 (add-local-hook 'post-command-hook 'set-list-mode-extent)
74 (add-hook 'post-command-hook 'set-list-mode-extent nil t) 100 (add-local-hook 'pre-command-hook 'list-mode-extent-pre-hook)
75 (make-local-hook 'pre-command-hook) 101 (set (make-local-variable 'next-line-add-newlines) nil)
76 (add-hook 'pre-command-hook 'list-mode-extent-pre-hook nil t)
77 (make-local-variable 'next-line-add-newlines)
78 (setq next-line-add-newlines nil)
79 (setq list-mode-extent nil) 102 (setq list-mode-extent nil)
80 ;; It is visually disconcerting to have the text cursor disappear within list 103 ;; It is visually disconcerting to have the text cursor disappear within list
81 ;; buffers, especially when moving from window to window, so leave it 104 ;; buffers, especially when moving from window to window, so leave it
82 ;; visible. -- Bob Weiner, 06/20/1999 105 ;; visible. -- Bob Weiner, 06/20/1999
83 ; (set-specifier text-cursor-visible-p nil (current-buffer)) 106 ; (set-specifier text-cursor-visible-p nil (current-buffer))
224 (defvar completion-highlight-first-word-only nil 247 (defvar completion-highlight-first-word-only nil
225 "*Completion will only highlight the first blank delimited word if t. 248 "*Completion will only highlight the first blank delimited word if t.
226 If the variable in not t or nil, the string is taken as a regexp to match for end 249 If the variable in not t or nil, the string is taken as a regexp to match for end
227 of highlight") 250 of highlight")
228 251
252 ;; see comment at list-mode-hook.
253 (put 'completion-setup-hook 'permanent-local t)
229 (defvar completion-setup-hook nil 254 (defvar completion-setup-hook nil
230 "Normal hook run at the end of setting up the text of a completion buffer.") 255 "Normal hook run at the end of setting up the text of a completion buffer.
256 When run, the completion buffer is the current buffer.")
231 257
232 ; Unnecessary FSFmacs crock. We frob the extents directly in 258 ; Unnecessary FSFmacs crock. We frob the extents directly in
233 ; display-completion-list, so no "heuristics" like this are necessary. 259 ; display-completion-list, so no "heuristics" like this are necessary.
234 ;(defvar completion-fixup-function nil 260 ;(defvar completion-fixup-function nil
235 ; "A function to customize how completions are identified in completion lists. 261 ; "A function to customize how completions are identified in completion lists.
263 :user-data 289 :user-data
264 Value passed to activation callback. 290 Value passed to activation callback.
265 :window-width 291 :window-width
266 If non-nil, width to use in displaying the list, instead of the 292 If non-nil, width to use in displaying the list, instead of the
267 actual window's width. 293 actual window's width.
294 :window-height
295 If non-nil, use no more than this many lines, and extend line width as
296 necessary.
268 :help-string (default is the value of `completion-default-help-string') 297 :help-string (default is the value of `completion-default-help-string')
269 Form to evaluate to get a string to insert at the beginning of 298 Form to evaluate to get a string to insert at the beginning of
270 the completion list buffer. This is evaluated when that buffer 299 the completion list buffer. This is evaluated when that buffer
271 is the current buffer and after it has been put into 300 is the current buffer and after it has been put into
272 completion-list-mode. 301 completion-list-mode.
286 ((:activate-callback 'default-choose-completion) 315 ((:activate-callback 'default-choose-completion)
287 :user-data 316 :user-data
288 :reference-buffer 317 :reference-buffer
289 (:help-string completion-default-help-string) 318 (:help-string completion-default-help-string)
290 (:completion-string "Possible completions are:") 319 (:completion-string "Possible completions are:")
291 :window-width) 320 :window-width
321 :window-height)
292 () 322 ()
293 (let ((old-buffer (current-buffer)) 323 (let ((old-buffer (current-buffer))
294 (bufferp (bufferp standard-output))) 324 (bufferp (bufferp standard-output)))
295 (if bufferp 325 (if bufferp
296 (set-buffer standard-output)) 326 (set-buffer standard-output))
313 ;; just in case. 343 ;; just in case.
314 (frame-width (or (last-nonminibuf-frame) 344 (frame-width (or (last-nonminibuf-frame)
315 (selected-frame))) 345 (selected-frame)))
316 80)))) 346 80))))
317 (let ((count 0) 347 (let ((count 0)
318 (max-width 0)) 348 (max-width 0)
349 old-max-width)
319 ;; Find longest completion 350 ;; Find longest completion
320 (let ((tail completions)) 351 (let ((tail completions))
321 (while tail 352 (while tail
322 (let* ((elt (car tail)) 353 (let* ((elt (car tail))
323 (len (cond ((stringp elt) 354 (len (cond ((stringp elt)
334 (setq max-width len)) 365 (setq max-width len))
335 (setq count (1+ count) 366 (setq count (1+ count)
336 tail (cdr tail))))) 367 tail (cdr tail)))))
337 368
338 (setq max-width (+ 2 max-width)) ; at least two chars between cols 369 (setq max-width (+ 2 max-width)) ; at least two chars between cols
370 (setq old-max-width max-width)
339 (let ((rows (let ((cols (min (/ win-width max-width) count))) 371 (let ((rows (let ((cols (min (/ win-width max-width) count)))
340 (if (<= cols 1) 372 (if (<= cols 1)
341 count 373 count
342 (progn 374 (progn
343 ;; re-space the columns 375 ;; re-space the columns
344 (setq max-width (/ win-width cols)) 376 (setq max-width (/ win-width cols))
345 (if (/= (% count cols) 0) ; want ceiling... 377 (if (/= (% count cols) 0) ; want ceiling...
346 (1+ (/ count cols)) 378 (1+ (/ count cols))
347 (/ count cols))))))) 379 (/ count cols)))))))
348 (if (stringp cl-completion-string) 380 (when
349 (princ (gettext cl-completion-string))) 381 (and cl-window-height
382 (> rows cl-window-height))
383 (setq max-width old-max-width)
384 (setq rows cl-window-height))
385 (when (and (stringp cl-completion-string)
386 (> (length cl-completion-string) 0))
387 (princ (gettext cl-completion-string))
388 (terpri))
350 (let ((tail completions) 389 (let ((tail completions)
351 (r 0) 390 (r 0)
352 (regexp-string 391 (regexp-string
353 (if (eq t 392 (if (eq t
354 completion-highlight-first-word-only) 393 completion-highlight-first-word-only)
355 "[ \t]" 394 "[ \t]"
356 completion-highlight-first-word-only))) 395 completion-highlight-first-word-only)))
357 (while (< r rows) 396 (while (< r rows)
358 (terpri) 397 (and (> r 0) (terpri))
359 (let ((indent 0) 398 (let ((indent 0)
360 (column 0) 399 (column 0)
361 (tail2 tail)) 400 (tail2 tail))
362 (while tail2 401 (while tail2
363 (let ((elt (car tail2))) 402 (let ((elt (car tail2)))
423 ;; (funcall completion-fixup-function)) 462 ;; (funcall completion-fixup-function))
424 ;; (put-text-property beg (point) 'mouse-face 'highlight) 463 ;; (put-text-property beg (point) 'mouse-face 'highlight)
425 ;; (put-text-property beg (point) 'list-mode-item t) 464 ;; (put-text-property beg (point) 'list-mode-item t)
426 ;; (goto-char end))))) 465 ;; (goto-char end)))))
427 )) 466 ))
428 (run-hooks 'completion-setup-hook))) 467 (save-excursion
468 (set-buffer standard-output)
469 (run-hooks 'completion-setup-hook))))
429 470
430 (defvar completion-display-completion-list-function 'display-completion-list 471 (defvar completion-display-completion-list-function 'display-completion-list
431 "Function to set up the list of completions in the completion buffer. 472 "Function to set up the list of completions in the completion buffer.
432 The function is called with one argument, the sorted list of completions. 473 The function is called with one argument, the sorted list of completions.
433 Particular minibuffer interface functions (e.g. `read-file-name') may 474 Particular minibuffer interface functions (e.g. `read-file-name') may