diff options
| author | Stefan Monnier | 2009-08-31 05:47:06 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2009-08-31 05:47:06 +0000 |
| commit | 4e135dd27f8497c456ee27c6d4938a6d8529bd4f (patch) | |
| tree | 1bb17ea5e04e9a579033e7ff02cc2db248c6bdf2 | |
| parent | 254bb2e698841d2962def44f1ee9d6849cd67197 (diff) | |
| download | emacs-4e135dd27f8497c456ee27c6d4938a6d8529bd4f.tar.gz emacs-4e135dd27f8497c456ee27c6d4938a6d8529bd4f.zip | |
(displayed-completions): Remove.
(symbol-complete): Use minibuffer-complete.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/progmodes/sym-comp.el | 95 |
2 files changed, 39 insertions, 61 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 22656cdc1f4..3db71bac2a4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2009-08-31 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * progmodes/sym-comp.el (displayed-completions): Remove. | ||
| 4 | (symbol-complete): Use minibuffer-complete. | ||
| 5 | |||
| 1 | 2009-08-31 Glenn Morris <rgm@gnu.org> | 6 | 2009-08-31 Glenn Morris <rgm@gnu.org> |
| 2 | 7 | ||
| 3 | * emacs-lisp/byte-run.el (define-obsolete-face-alias): New macro. | 8 | * emacs-lisp/byte-run.el (define-obsolete-face-alias): New macro. |
diff --git a/lisp/progmodes/sym-comp.el b/lisp/progmodes/sym-comp.el index cb0c0b7f6d2..ed49c9d1f83 100644 --- a/lisp/progmodes/sym-comp.el +++ b/lisp/progmodes/sym-comp.el | |||
| @@ -57,7 +57,12 @@ point." | |||
| 57 | (defvar symbol-completion-symbol-function 'symbol-completion-symbol | 57 | (defvar symbol-completion-symbol-function 'symbol-completion-symbol |
| 58 | "Function to return a partial symbol before point for completion. | 58 | "Function to return a partial symbol before point for completion. |
| 59 | The value it returns should be a string (or nil). | 59 | The value it returns should be a string (or nil). |
| 60 | Major modes may set this locally if the default isn't appropriate.") | 60 | Major modes may set this locally if the default isn't appropriate. |
| 61 | |||
| 62 | Beware: the length of the string STR returned need to be equal to the length | ||
| 63 | of text before point that's subject to completion. Typically, this amounts | ||
| 64 | to saying that STR is equal to | ||
| 65 | \(buffer-substring (- (point) (length STR)) (point)).") | ||
| 61 | 66 | ||
| 62 | (defvar symbol-completion-completions-function nil | 67 | (defvar symbol-completion-completions-function nil |
| 63 | "Function to return possible symbol completions. | 68 | "Function to return possible symbol completions. |
| @@ -97,7 +102,7 @@ The predicate being used for selecting completions (from | |||
| 97 | dynamically-bound as `symbol-completion-predicate' in case the | 102 | dynamically-bound as `symbol-completion-predicate' in case the |
| 98 | transform needs it.") | 103 | transform needs it.") |
| 99 | 104 | ||
| 100 | (defvar displayed-completions) | 105 | (defvar symbol-completion-predicate) |
| 101 | 106 | ||
| 102 | ;;;###autoload | 107 | ;;;###autoload |
| 103 | (defun symbol-complete (&optional predicate) | 108 | (defun symbol-complete (&optional predicate) |
| @@ -119,63 +124,33 @@ to be set buffer-locally. Variables `symbol-completion-symbol-function', | |||
| 119 | ;; Fixme: Punt to `complete-symbol' in this case? | 124 | ;; Fixme: Punt to `complete-symbol' in this case? |
| 120 | (unless (functionp symbol-completion-completions-function) | 125 | (unless (functionp symbol-completion-completions-function) |
| 121 | (error "symbol-completion-completions-function not defined")) | 126 | (error "symbol-completion-completions-function not defined")) |
| 122 | (let ((window (get-buffer-window "*Completions*"))) | 127 | (let* ((pattern (or (funcall symbol-completion-symbol-function) |
| 123 | (let* ((pattern (or (funcall symbol-completion-symbol-function) | 128 | (error "No preceding symbol to complete"))) |
| 124 | (error "No preceding symbol to complete"))) | 129 | ;; FIXME: We assume below that `pattern' holds the text just |
| 125 | (predicate (or predicate | 130 | ;; before point. This is a problem in the way |
| 126 | (if symbol-completion-predicate-function | 131 | ;; symbol-completion-symbol-function was defined. |
| 127 | (funcall symbol-completion-predicate-function | 132 | (predicate (or predicate |
| 128 | (- (point) (length pattern)) | 133 | (if symbol-completion-predicate-function |
| 129 | (point))))) | 134 | (funcall symbol-completion-predicate-function |
| 130 | (completions (funcall symbol-completion-completions-function | 135 | (- (point) (length pattern)) |
| 131 | pattern)) | 136 | (point))))) |
| 132 | (completion (try-completion pattern completions predicate))) | 137 | (completions (funcall symbol-completion-completions-function |
| 133 | ;; If this command was repeated, and there's a fresh completion | 138 | pattern)) |
| 134 | ;; window with a live buffer and a displayed completion list | 139 | ;; In case the transform needs to access it. |
| 135 | ;; matching the current completions, then scroll the window. | 140 | (symbol-completion-predicate predicate) |
| 136 | (unless (and (eq last-command this-command) | 141 | (completion-annotate-function |
| 137 | window (window-live-p window) (window-buffer window) | 142 | (if (functionp symbol-completion-transform-function) |
| 138 | (buffer-name (window-buffer window)) | 143 | (lambda (str) |
| 139 | (with-current-buffer (window-buffer window) | 144 | (car-safe (cdr-safe |
| 140 | (if (equal displayed-completions | 145 | (funcall symbol-completion-transform-function |
| 141 | (all-completions pattern completions predicate)) | 146 | str)))))) |
| 142 | (progn | 147 | (minibuffer-completion-table completions) |
| 143 | (if (pos-visible-in-window-p (point-max) window) | 148 | (minibuffer-completion-predicate predicate) |
| 144 | (set-window-start window (point-min)) | 149 | (ol (make-overlay (- (point) (length pattern)) (point) nil nil t))) |
| 145 | (save-selected-window | 150 | (overlay-put ol 'field 'sym-comp) |
| 146 | (select-window window) | 151 | (unwind-protect |
| 147 | (scroll-up))) | 152 | (call-interactively 'minibuffer-complete) |
| 148 | t)))) | 153 | (delete-overlay ol)))) |
| 149 | ;; Otherwise, do completion. | ||
| 150 | (cond ((eq completion t)) | ||
| 151 | ((null completion) | ||
| 152 | (message "Can't find completion for \"%s\"" pattern) | ||
| 153 | (ding)) | ||
| 154 | ((not (string= pattern completion)) | ||
| 155 | (delete-region (- (point) (length pattern)) (point)) | ||
| 156 | (insert completion)) | ||
| 157 | (t | ||
| 158 | (message "Making completion list...") | ||
| 159 | (let* ((list (all-completions pattern completions predicate)) | ||
| 160 | ;; In case the transform needs to access it. | ||
| 161 | (symbol-completion-predicate predicate) | ||
| 162 | ;; Copy since list is side-effected by sorting. | ||
| 163 | (copy (copy-sequence list))) | ||
| 164 | (setq list (sort list 'string<)) | ||
| 165 | (if (functionp symbol-completion-transform-function) | ||
| 166 | (setq list | ||
| 167 | (mapcar (funcall | ||
| 168 | symbol-completion-transform-function) | ||
| 169 | list))) | ||
| 170 | (with-output-to-temp-buffer "*Completions*" | ||
| 171 | (condition-case () | ||
| 172 | (display-completion-list list pattern) ; Emacs 22 | ||
| 173 | (error (display-completion-list list)))) | ||
| 174 | ;; Record the list for determining whether to scroll | ||
| 175 | ;; (above). | ||
| 176 | (with-current-buffer "*Completions*" | ||
| 177 | (set (make-local-variable 'displayed-completions) copy))) | ||
| 178 | (message "Making completion list...%s" "done"))))))) | ||
| 179 | 154 | ||
| 180 | (eval-when-compile (require 'hippie-exp)) | 155 | (eval-when-compile (require 'hippie-exp)) |
| 181 | 156 | ||
| @@ -246,8 +221,6 @@ completion: | |||
| 246 | ;; Else, we assume that a function name is expected. | 221 | ;; Else, we assume that a function name is expected. |
| 247 | 'fboundp)))) | 222 | 'fboundp)))) |
| 248 | 223 | ||
| 249 | (defvar symbol-completion-predicate) | ||
| 250 | |||
| 251 | (defun lisp-symbol-completion-transform () | 224 | (defun lisp-symbol-completion-transform () |
| 252 | "`symbol-completion-transform-function' for Lisp." | 225 | "`symbol-completion-transform-function' for Lisp." |
| 253 | (lambda (elt) | 226 | (lambda (elt) |