changeset 39564:0e059993ad95

(lisp-imenu-generic-expression): Use regexp-opt. (doc-string-elt): Set symbol's prop. Copied from autoload.el. (lisp-font-lock-syntactic-face-function): New function. (lisp-mode-variables): Use it. Make arg optional. (emacs-lisp-mode): Don't pass an arg to lisp-mode-variables. (lisp-mode): Don't pass an arg to lisp-mode-variables. Set comment-start-skip.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 05 Oct 2001 09:31:27 +0000
parents 925776635a57
children e03e925846db
files lisp/emacs-lisp/lisp-mode.el
diffstat 1 files changed, 77 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emacs-lisp/lisp-mode.el	Fri Oct 05 09:30:59 2001 +0000
+++ b/lisp/emacs-lisp/lisp-mode.el	Fri Oct 05 09:31:27 2001 +0000
@@ -83,19 +83,78 @@
 (defvar lisp-imenu-generic-expression
   (list
    (list nil
-	 (purecopy "^\\s-*(def\\(un\\*?\\|subst\\|macro\\|advice\\|\
-ine-skeleton\\|ine-minor-mode\\)\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)") 2)
+	 (purecopy (concat "^\\s-*("
+			   (eval-when-compile
+			     (regexp-opt
+			      '("defun" "defun*" "defsubst" "defmacro"
+				"defadvice" "define-skeleton"
+				"define-minor-mode" "define-derived-mode"
+				"define-compiler-macro" "define-modify-macro"
+				"defsetf" "define-setf-expander"
+				"define-method-combination"
+				"defgeneric" "defmethod") t)
+			     "\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)")))
+	 2)
    (list (purecopy "Variables")
-	 (purecopy "^\\s-*(def\\(var\\|const\\|custom\\)\\s-+\
-\\(\\sw\\(\\sw\\|\\s_\\)+\\)") 2)
+	 (purecopy (concat "^\\s-*("
+			   (eval-when-compile
+			     (regexp-opt
+			      '("defvar" "defconst" "defconstant" "defcustom"
+				"defparameter" "define-symbol-macro") t)
+			     "\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)")))
+	 2)
    (list (purecopy "Types")
-	 (purecopy "^\\s-*(def\\(group\\|type\\|struct\\|class\\|\
-ine-condition\\|ine-widget\\|face\\)\\s-+'?\\(\\sw\\(\\sw\\|\\s_\\)+\\)")
+	 (purecopy (concat "^\\s-*("
+			   (eval-when-compile
+			     (regexp-opt
+			      '("defgroup" "deftype" "defstruct" "defclass"
+				"define-condition" "define-widget" "defface"
+				"defpackage") t)
+			     "\\s-+'?\\(\\sw\\(\\sw\\|\\s_\\)+\\)")))
 	 2))
 
   "Imenu generic expression for Lisp mode.  See `imenu-generic-expression'.")
 
-(defun lisp-mode-variables (lisp-syntax)
+;; This was originally in autoload.el and is still used there.
+(put 'autoload 'doc-string-elt 3)
+(put 'defun    'doc-string-elt 3)
+(put 'defun*    'doc-string-elt 3)
+(put 'defvar   'doc-string-elt 3)
+(put 'defcustom 'doc-string-elt 3)
+(put 'defconst 'doc-string-elt 3)
+(put 'defmacro 'doc-string-elt 3)
+(put 'defsubst 'doc-string-elt 3)
+(put 'define-skeleton 'doc-string-elt 2)
+(put 'define-derived-mode 'doc-string-elt 4)
+(put 'easy-mmode-define-minor-mode 'doc-string-elt 2)
+(put 'define-minor-mode 'doc-string-elt 2)
+(put 'define-generic-mode 'doc-string-elt 7)
+;; define-global-mode has no explicit docstring.
+(put 'easy-mmode-define-global-mode 'doc-string-elt 0)
+
+
+(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 (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 (or (get sym 'doc-string-elt) 3)))))))
+	  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
+;; (uselessly) passed from pp.el, chistory.el, gnus-kill.el and score-mode.el
+(defun lisp-mode-variables (&optional lisp-syntax)
   (cond (lisp-syntax
 	  (set-syntax-table lisp-mode-syntax-table)))
   (setq local-abbrev-table lisp-mode-abbrev-table)
@@ -144,7 +203,9 @@
 	'((lisp-font-lock-keywords
 	   lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
 	  nil nil (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
-	  (font-lock-mark-block-function . mark-defun))))
+	  (font-lock-mark-block-function . mark-defun)
+	  (font-lock-syntactic-face-function
+	   . lisp-font-lock-syntactic-face-function))))
 
 (defun lisp-outline-level ()
   "Lisp mode `outline-level' function."
@@ -248,7 +309,7 @@
 \\{emacs-lisp-mode-map}
 Entry to this mode calls the value of `emacs-lisp-mode-hook'
 if that value is non-nil."
-  (lisp-mode-variables nil)
+  (lisp-mode-variables)
   (setq imenu-case-fold-search nil))
 
 (defvar lisp-mode-map
@@ -271,9 +332,10 @@
 
 Entry to this mode calls the value of `lisp-mode-hook'
 if that value is non-nil."
-  (lisp-mode-variables t)
-  (make-local-variable 'font-lock-keywords-case-fold-search)
-  (setq font-lock-keywords-case-fold-search t)
+  (lisp-mode-variables)
+  (set (make-local-variable 'comment-start-skip)
+       "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *")
+  (set (make-local-variable 'font-lock-keywords-case-fold-search) t)
   (setq imenu-case-fold-search t))
 
 ;; This will do unless inf-lisp.el is loaded.
@@ -573,10 +635,9 @@
 With argument, indent any additional lines of the same expression
 rigidly along with this one."
   (interactive "P")
-  (let ((indent (calculate-lisp-indent)) shift-amt beg end
-	(pos (- (point-max) (point))))
-    (beginning-of-line)
-    (setq beg (point))
+  (let ((indent (calculate-lisp-indent)) shift-amt end
+	(pos (- (point-max) (point)))
+	(beg (progn (beginning-of-line) (point))))
     (skip-chars-forward " \t")
     (if (or (null indent) (looking-at "\\s<\\s<\\s<"))
 	;; Don't alter indentation of a ;;; comment line