[slime-cvs] CVS slime
mkoeppe
mkoeppe at common-lisp.net
Tue Feb 21 06:44:26 UTC 2006
Update of /project/slime/cvsroot/slime
In directory common-lisp:/tmp/cvs-serv21305
Modified Files:
slime.el
Log Message:
(slime-complete-keywords-contextually): New
customizable variable.
(slime-enclosing-operator-names): New optional argument
max-levels.
(slime-completions-for-keyword): New.
(slime-contextual-completions): New.
(slime-expand-abbreviations-and-complete): Use it instead of
slime-completions.
--- /project/slime/cvsroot/slime/slime.el 2006/02/20 08:03:44 1.584
+++ /project/slime/cvsroot/slime/slime.el 2006/02/21 06:44:26 1.585
@@ -215,6 +215,12 @@
:group 'slime-mode
:type 'boolean)
+(defcustom slime-complete-keywords-contextually t
+ "Use information from the arglist of the surrounding function call
+to complete keywords."
+ :group 'slime-mode
+ :type 'boolean)
+
(defcustom slime-space-information-p t
"Have the SPC key offer arglist information."
:type 'boolean
@@ -5575,7 +5581,7 @@
(let* ((end (move-marker (make-marker) (slime-symbol-end-pos)))
(beg (move-marker (make-marker) (slime-symbol-start-pos)))
(prefix (buffer-substring-no-properties beg end))
- (completion-result (slime-completions prefix))
+ (completion-result (slime-contextual-completions beg end))
(completion-set (first completion-result))
(completed-prefix (second completion-result)))
(if (null completion-set)
@@ -5717,12 +5723,37 @@
alist but ignores CDRs."
(mapcar (lambda (x) (cons x nil)) list))
+(defun* slime-contextual-completions (beg end)
+ "Return a list of completions of the token from BEG to END in the
+current buffer."
+ (let ((token (buffer-substring-no-properties beg end)))
+ (when (and (< beg (point-max))
+ (string= (buffer-substring-no-properties beg (1+ beg)) ":"))
+ ;; Contextual keyword completion
+ (let ((operator-names (save-excursion
+ (goto-char beg)
+ (slime-enclosing-operator-names 1))))
+ (when operator-names
+ (let ((completions
+ (slime-completions-for-keyword (first operator-names) token)))
+ (when (first completions)
+ (return-from slime-contextual-completions completions))
+ ;; If no matching keyword was found, do regular symbol
+ ;; completion.
+ ))))
+ ;; Regular symbol completion
+ (slime-completions (buffer-substring-no-properties beg end))))
+
(defun slime-completions (prefix)
(slime-eval `(swank:completions ,prefix ',(slime-current-package))))
(defun slime-simple-completions (prefix)
(slime-eval `(swank:simple-completions ,prefix ',(slime-current-package))))
+(defun slime-completions-for-keyword (operator-designator prefix)
+ (slime-eval `(swank:completions-for-keyword ',operator-designator
+ ,prefix)))
+
;;;; Fuzzy completion
@@ -9750,17 +9781,21 @@
(forward-char 1)
(slime-symbol-name-at-point)))))
-(defun slime-enclosing-operator-names ()
- "Return the list of operator names of the forms containing point."
- (let ((result '()))
+(defun slime-enclosing-operator-names (&optional max-levels)
+ "Return the list of operator names of the forms containing point.
+When MAX-LEVELS is non-nil, go up at most this many levels of parens."
+ (let ((result '())
+ (level 1))
(ignore-errors
(save-restriction
(narrow-to-region (save-excursion (beginning-of-defun) (point))
(point))
(save-excursion
- (while t
+ (while (or (not max-levels)
+ (<= level max-levels))
(backward-up-list 1)
(when (looking-at "(")
+ (incf level)
(forward-char 1)
(when-let (name (slime-symbol-name-at-point))
;; Detect MAKE-INSTANCE forms and collect the class-name
More information about the slime-cvs
mailing list