From c0752bdcf73a29a2ebb23d2a4a8e3f01cad9b22b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 4 Oct 2005 21:49:09 +0000 Subject: Move comments into docstrings. (eldoc-message-commands): Initialize in its declaration. Add move-beginning-of-line and move-end-of-line. (eldoc-add-command, eldoc-add-command-completions) (eldoc-remove-command, eldoc-remove-command-completions): Simplify. --- lisp/emacs-lisp/eldoc.el | 109 +++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 65 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el index 4ae8f53a981..7712ab5af1c 100644 --- a/lisp/emacs-lisp/eldoc.el +++ b/lisp/emacs-lisp/eldoc.el @@ -103,37 +103,37 @@ truncated to make more of the arglist or documentation string visible." ;;; No user options below here. -;; Commands after which it is appropriate to print in the echo area. -;; Eldoc does not try to print function arglists, etc. after just any command, -;; because some commands print their own messages in the echo area and these -;; functions would instantly overwrite them. But self-insert-command as well -;; as most motion commands are good candidates. -;; This variable contains an obarray of symbols; do not manipulate it -;; directly. Instead, use `eldoc-add-command' and `eldoc-remove-command'. -(defvar eldoc-message-commands nil) - -;; This is used by eldoc-add-command to initialize eldoc-message-commands -;; as an obarray. -;; It should probably never be necessary to do so, but if you -;; choose to increase the number of buckets, you must do so before loading -;; this file since the obarray is initialized at load time. -;; Remember to keep it a prime number to improve hash performance. -(defvar eldoc-message-commands-table-size 31) - -;; Bookkeeping; elements are as follows: -;; 0 - contains the last symbol read from the buffer. -;; 1 - contains the string last displayed in the echo area for that -;; symbol, so it can be printed again if necessary without reconsing. -;; 2 - 'function if function args, 'variable if variable documentation. -(defvar eldoc-last-data (make-vector 3 nil)) +(defvar eldoc-message-commands-table-size 31 + "This is used by eldoc-add-command to initialize eldoc-message-commands +as an obarray. +It should probably never be necessary to do so, but if you +choose to increase the number of buckets, you must do so before loading +this file since the obarray is initialized at load time. +Remember to keep it a prime number to improve hash performance.") + +(defconst eldoc-message-commands + (make-vector eldoc-message-commands-table-size 0) + "Commands after which it is appropriate to print in the echo area. +Eldoc does not try to print function arglists, etc. after just any command, +because some commands print their own messages in the echo area and these +functions would instantly overwrite them. But self-insert-command as well +as most motion commands are good candidates. +This variable contains an obarray of symbols; do not manipulate it +directly. Instead, use `eldoc-add-command' and `eldoc-remove-command'.") + +(defconst eldoc-last-data (make-vector 3 nil) + "Bookkeeping; elements are as follows: + 0 - contains the last symbol read from the buffer. + 1 - contains the string last displayed in the echo area for that + symbol, so it can be printed again if necessary without reconsing. + 2 - 'function if function args, 'variable if variable documentation.") (defvar eldoc-last-message nil) -;; eldoc's timer object. -(defvar eldoc-timer nil) +(defvar eldoc-timer nil "eldoc's timer object.") -;; idle time delay currently in use by timer. -;; This is used to determine if eldoc-idle-delay is changed by the user. -(defvar eldoc-current-idle-delay eldoc-idle-delay) +(defvar eldoc-current-idle-delay eldoc-idle-delay + "idle time delay currently in use by timer. +This is used to determine if `eldoc-idle-delay' is changed by the user.") ;;;###autoload @@ -408,53 +408,32 @@ Emacs Lisp mode) that support Eldoc.") ;; These functions do display-command table management. (defun eldoc-add-command (&rest cmds) - (or eldoc-message-commands - (setq eldoc-message-commands - (make-vector eldoc-message-commands-table-size 0))) - - (let (name sym) - (while cmds - (setq name (car cmds)) - (setq cmds (cdr cmds)) - - (cond ((symbolp name) - (setq sym name) - (setq name (symbol-name sym))) - ((stringp name) - (setq sym (intern-soft name)))) - - (and (symbolp sym) - (fboundp sym) - (set (intern name eldoc-message-commands) t))))) + (dolist (name cmds) + (and (symbolp name) + (setq name (symbol-name name))) + (set (intern name eldoc-message-commands) t))) (defun eldoc-add-command-completions (&rest names) - (while names - (apply 'eldoc-add-command - (all-completions (car names) obarray 'fboundp)) - (setq names (cdr names)))) + (dolist (name names) + (apply 'eldoc-add-command (all-completions name obarray 'commandp)))) (defun eldoc-remove-command (&rest cmds) - (let (name) - (while cmds - (setq name (car cmds)) - (setq cmds (cdr cmds)) - - (and (symbolp name) - (setq name (symbol-name name))) - - (unintern name eldoc-message-commands)))) + (dolist (name cmds) + (and (symbolp name) + (setq name (symbol-name name))) + (unintern name eldoc-message-commands))) (defun eldoc-remove-command-completions (&rest names) - (while names + (dolist (name names) (apply 'eldoc-remove-command - (all-completions (car names) eldoc-message-commands)) - (setq names (cdr names)))) + (all-completions name eldoc-message-commands)))) ;; Prime the command list. (eldoc-add-command-completions - "backward-" "beginning-of-" "delete-other-windows" "delete-window" - "end-of-" "exchange-point-and-mark" "forward-" + "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows" + "delete-window" + "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-" "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph" "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window" "previous-" "recenter" "scroll-" "self-insert-command" @@ -462,5 +441,5 @@ Emacs Lisp mode) that support Eldoc.") (provide 'eldoc) -;;; arch-tag: c9a58f9d-2055-46c1-9b82-7248b71a8375 +;; arch-tag: c9a58f9d-2055-46c1-9b82-7248b71a8375 ;;; eldoc.el ends here -- cgit v1.2.3 From efbbcafbbecd28a962fe20b9afc45c353c0d7245 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 5 Oct 2005 14:07:18 +0000 Subject: (lisp-font-lock-syntactic-face-function): Don't mark as docstring the 3rd elem of an unknown toplevel form. --- lisp/emacs-lisp/lisp-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index e50d5bd125c..b347c136adf 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -163,7 +163,7 @@ (let ((sym (intern-soft (buffer-substring (point) (progn (forward-sexp 1) (point)))))) - (eq n (or (get sym 'doc-string-elt) 3))))))) + (eq n (get sym 'doc-string-elt))))))) font-lock-doc-face font-lock-string-face) font-lock-comment-face)) -- cgit v1.2.3 From f8ab194748b1293ab97bc45f8a5519fa9acce569 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 5 Oct 2005 15:03:09 +0000 Subject: (lambda): Add its doc-string-elt property. (lisp-doc-string-elt-property): New var. (lisp-font-lock-syntactic-face-function): Use it. Rewrite to recognize docstrings even for forms not at toplevel. --- lisp/emacs-lisp/lisp-mode.el | 49 +++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index b347c136adf..c9786ad68d3 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -147,25 +147,42 @@ (put 'define-ibuffer-filter 'doc-string-elt 2) (put 'define-ibuffer-op 'doc-string-elt 3) (put 'define-ibuffer-sorter 'doc-string-elt 2) +(put 'lambda 'doc-string-elt 2) + +(defvar lisp-doc-string-elt-property 'doc-string-elt + "The symbol property that holds the docstring position info.") (defun lisp-font-lock-syntactic-face-function (state) (if (nth 3 state) - (if (and (eq (nth 0 state) 1) - ;; This might be a docstring. - (save-excursion - (let ((n 0)) - (goto-char (nth 8 state)) - (condition-case nil - (while (and (not (bobp)) - (progn (backward-sexp 1) (setq n (1+ n))))) - (scan-error nil)) - (when (> n 0) - (let ((sym (intern-soft - (buffer-substring - (point) (progn (forward-sexp 1) (point)))))) - (eq n (get sym 'doc-string-elt))))))) - font-lock-doc-face - font-lock-string-face) + ;; This might be a docstring. + (let* ((listbeg (nth 1 state)) + (firstsym (and listbeg + (save-excursion + (goto-char listbeg) + (and (looking-at "([ \t\n]*\\(\\(\\sw\\|\\s_\\)+\\)") + (match-string 1))))) + (docelt (and firstsym (get (intern-soft firstsym) + lisp-doc-string-elt-property)))) + (if (and docelt + ;; It's a string passed to a macro that has docstrings. + ;; Check whether it's in docstring position. + (let ((startpos (nth 8 state))) + (save-excursion + (when (functionp docelt) + (goto-char (match-end 1)) + (setq docelt (funcall docelt))) + (goto-char listbeg) + (forward-char 1) + (condition-case nil + (while (and (> docelt 0) (< (point) startpos) + (progn (forward-sexp 1) t)) + (setq docelt (1- docelt))) + (error nil)) + (and (zerop docelt) (<= (point) startpos) + (progn (forward-comment (point-max)) t) + (= (point) (nth 8 state)))))) + font-lock-doc-face + font-lock-string-face)) font-lock-comment-face)) ;; The LISP-SYNTAX argument is used by code in inf-lisp.el and is -- cgit v1.2.3 From d95af087de80d8309b92b38122451e660df0e398 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 5 Oct 2005 15:19:38 +0000 Subject: (lisp-mode-syntax-table): Move the nesting bit from # to |. (lisp-font-lock-syntactic-face-function): Distinguish |...| symbols. --- lisp/emacs-lisp/lisp-mode.el | 71 +++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index c9786ad68d3..c93eb0e62c4 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el @@ -59,9 +59,9 @@ (modify-syntax-entry ?\t " " table) (modify-syntax-entry ?\f " " table) (modify-syntax-entry ?\n "> " table) -;;; This is probably obsolete since nowadays such features use overlays. -;;; ;; Give CR the same syntax as newline, for selective-display. -;;; (modify-syntax-entry ?\^m "> " table) + ;; This is probably obsolete since nowadays such features use overlays. + ;; ;; Give CR the same syntax as newline, for selective-display. + ;; (modify-syntax-entry ?\^m "> " table) (modify-syntax-entry ?\; "< " table) (modify-syntax-entry ?` "' " table) (modify-syntax-entry ?' "' " table) @@ -82,8 +82,8 @@ (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table))) (modify-syntax-entry ?\[ "_ " table) (modify-syntax-entry ?\] "_ " table) - (modify-syntax-entry ?# "' 14bn" table) - (modify-syntax-entry ?| "\" 23b" table) + (modify-syntax-entry ?# "' 14b" table) + (modify-syntax-entry ?| "\" 23bn" table) table)) (define-abbrev-table 'lisp-mode-abbrev-table ()) @@ -154,35 +154,38 @@ (defun lisp-font-lock-syntactic-face-function (state) (if (nth 3 state) - ;; This might be a docstring. - (let* ((listbeg (nth 1 state)) - (firstsym (and listbeg - (save-excursion - (goto-char listbeg) - (and (looking-at "([ \t\n]*\\(\\(\\sw\\|\\s_\\)+\\)") - (match-string 1))))) - (docelt (and firstsym (get (intern-soft firstsym) - lisp-doc-string-elt-property)))) - (if (and docelt - ;; It's a string passed to a macro that has docstrings. - ;; Check whether it's in docstring position. - (let ((startpos (nth 8 state))) - (save-excursion - (when (functionp docelt) - (goto-char (match-end 1)) - (setq docelt (funcall docelt))) - (goto-char listbeg) - (forward-char 1) - (condition-case nil - (while (and (> docelt 0) (< (point) startpos) - (progn (forward-sexp 1) t)) - (setq docelt (1- docelt))) - (error nil)) - (and (zerop docelt) (<= (point) startpos) - (progn (forward-comment (point-max)) t) - (= (point) (nth 8 state)))))) - font-lock-doc-face - font-lock-string-face)) + ;; This might be a (doc)string or a |...| symbol. + (let ((startpos (nth 8 state))) + (if (eq (char-after startpos) ?|) + ;; This is not a string, but a |...| symbol. + nil + (let* ((listbeg (nth 1 state)) + (firstsym (and listbeg + (save-excursion + (goto-char listbeg) + (and (looking-at "([ \t\n]*\\(\\(\\sw\\|\\s_\\)+\\)") + (match-string 1))))) + (docelt (and firstsym (get (intern-soft firstsym) + lisp-doc-string-elt-property)))) + (if (and docelt + ;; It's a string in a form that can have a docstring. + ;; Check whether it's in docstring position. + (save-excursion + (when (functionp docelt) + (goto-char (match-end 1)) + (setq docelt (funcall docelt))) + (goto-char listbeg) + (forward-char 1) + (condition-case nil + (while (and (> docelt 0) (< (point) startpos) + (progn (forward-sexp 1) t)) + (setq docelt (1- docelt))) + (error nil)) + (and (zerop docelt) (<= (point) startpos) + (progn (forward-comment (point-max)) t) + (= (point) (nth 8 state))))) + font-lock-doc-face + font-lock-string-face)))) font-lock-comment-face)) ;; The LISP-SYNTAX argument is used by code in inf-lisp.el and is -- cgit v1.2.3