Commit 535eadac authored by Dave Love's avatar Dave Love
Browse files

(emacs-lisp-mode-syntax-table)

(lisp-mode-map, lisp-interaction-mode-map): Define all inside
defvar.
(lisp-mode-syntax-table): Set up for #|...|# comments.
(lisp-imenu-generic-expression): Purecopy strings.  Use syntax
classes.  Match `defface'.
(emacs-lisp-mode-hook): Add checkdoc-minor-mode to options.
(eval-defun-1): Fix for defcustom.
(lisp-indent-region): Doc fix.
parent 69b05ea4
;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands. ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands.
;; Copyright (C) 1985, 1986, 1999 Free Software Foundation, Inc. ;; Copyright (C) 1985, 1986, 1999, 2000 Free Software Foundation, Inc.
;; Maintainer: FSF ;; Maintainer: FSF
;; Keywords: lisp, languages ;; Keywords: lisp, languages
...@@ -25,79 +25,81 @@ ...@@ -25,79 +25,81 @@
;;; Commentary: ;;; Commentary:
;; The base major mode for editing Lisp code (used also for Emacs Lisp). ;; The base major mode for editing Lisp code (used also for Emacs Lisp).
;; This mode is documented in the Emacs manual ;; This mode is documented in the Emacs manual.
;;; Code: ;;; Code:
(defvar lisp-mode-syntax-table nil "") (defvar lisp-mode-abbrev-table nil)
(defvar emacs-lisp-mode-syntax-table nil "")
(defvar lisp-mode-abbrev-table nil "")
(if (not emacs-lisp-mode-syntax-table) (defvar emacs-lisp-mode-syntax-table
(let ((table (make-syntax-table)))
(let ((i 0)) (let ((i 0))
(setq emacs-lisp-mode-syntax-table (make-syntax-table))
(while (< i ?0) (while (< i ?0)
(modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) (modify-syntax-entry i "_ " table)
(setq i (1+ i))) (setq i (1+ i)))
(setq i (1+ ?9)) (setq i (1+ ?9))
(while (< i ?A) (while (< i ?A)
(modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) (modify-syntax-entry i "_ " table)
(setq i (1+ i))) (setq i (1+ i)))
(setq i (1+ ?Z)) (setq i (1+ ?Z))
(while (< i ?a) (while (< i ?a)
(modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) (modify-syntax-entry i "_ " table)
(setq i (1+ i))) (setq i (1+ i)))
(setq i (1+ ?z)) (setq i (1+ ?z))
(while (< i 128) (while (< i 128)
(modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) (modify-syntax-entry i "_ " table)
(setq i (1+ i))) (setq i (1+ i)))
(modify-syntax-entry ? " " emacs-lisp-mode-syntax-table) (modify-syntax-entry ? " " table)
(modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\t " " table)
(modify-syntax-entry ?\f " " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\f " " table)
(modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\n "> " table)
;; Give CR the same syntax as newline, for selective-display. ;; Give CR the same syntax as newline, for selective-display.
(modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\^m "> " table)
(modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\; "< " table)
(modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?` "' " table)
(modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?' "' " table)
(modify-syntax-entry ?, "' " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?, "' " table)
;; Used to be singlequote; changed for flonums. ;; Used to be singlequote; changed for flonums.
(modify-syntax-entry ?. "_ " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?. "_ " table)
(modify-syntax-entry ?# "' " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?# "' " table)
(modify-syntax-entry ?\" "\" " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\" "\" " table)
(modify-syntax-entry ?\\ "\\ " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\\ "\\ " table)
(modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\( "() " table)
(modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\) ")( " table)
(modify-syntax-entry ?\[ "(] " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\[ "(] " table)
(modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\] ")[ " table)
;; All non-word multibyte characters should be `symbol'. ;; All non-word multibyte characters should be `symbol'.
(map-char-table (map-char-table
(function (lambda (key val) (function (lambda (key val)
(and (>= key 256) (and (>= key 256)
(/= (char-syntax key) ?w) (/= (char-syntax key) ?w)
(modify-syntax-entry key "_ " (modify-syntax-entry key "_ "
emacs-lisp-mode-syntax-table)))) table))))
(standard-syntax-table)))) (standard-syntax-table)))
table))
(if (not lisp-mode-syntax-table)
(progn (setq lisp-mode-syntax-table (defvar lisp-mode-syntax-table
(copy-syntax-table emacs-lisp-mode-syntax-table)) (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
(modify-syntax-entry ?\| "\" " lisp-mode-syntax-table) (modify-syntax-entry ?\| "\" " table)
(modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table) (modify-syntax-entry ?\[ "_ " table)
(modify-syntax-entry ?\] "_ " lisp-mode-syntax-table))) (modify-syntax-entry ?\] "_ " table)
(modify-syntax-entry ?# "' 14bn" table)
(modify-syntax-entry ?| "' 23b" table)
table))
(define-abbrev-table 'lisp-mode-abbrev-table ()) (define-abbrev-table 'lisp-mode-abbrev-table ())
(defvar lisp-imenu-generic-expression (defvar lisp-imenu-generic-expression
'( (list
(nil (list nil
"^\\s-*(def\\(un\\|subst\\|macro\\|advice\\|ine-skeleton\\)\ (purecopy "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\|\
\\s-+\\([-A-Za-z0-9+*|:/]+\\)" 2) ine-skeleton\\|ine-minor-mode\\)\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)") 2)
("Variables" (list (purecopy "Variables")
"^\\s-*(def\\(var\\|const\\|custom\\)\\s-+\\([-A-Za-z0-9+*|:/]+\\)" 2) (purecopy "^\\s-*(def\\(var\\|const\\|custom\\)\\s-+\
("Types" \\(\\sw\\(\\sw\\|\\s_\\)+\\)") 2)
"^\\s-*(def\\(group\\|type\\|struct\\|class\\|ine-condition\ (list (purecopy "Types")
\\|ine-widget\\)\\s-+'?\\([-A-Za-z0-9+*|:/]+\\)" (purecopy "^\\s-*(def\\(group\\|type\\|struct\\|class\\|\
ine-condition\\|ine-widget\\|face\\)\\s-+'?\\(\\sw\\(\\sw\\|\\s_\\)+\\)")
2)) 2))
"Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.")
...@@ -210,7 +212,7 @@ All commands in `shared-lisp-mode-map' are inherited by this map.") ...@@ -210,7 +212,7 @@ All commands in `shared-lisp-mode-map' are inherited by this map.")
(require 'bytecomp) (require 'bytecomp)
;; Recompile if file or buffer has changed since last compilation. ;; Recompile if file or buffer has changed since last compilation.
(if (and (buffer-modified-p) (if (and (buffer-modified-p)
(y-or-n-p (format "save buffer %s first? " (buffer-name)))) (y-or-n-p (format "Save buffer %s first? " (buffer-name))))
(save-buffer)) (save-buffer))
(let ((compiled-file-name (byte-compile-dest-file buffer-file-name))) (let ((compiled-file-name (byte-compile-dest-file buffer-file-name)))
(if (file-newer-than-file-p compiled-file-name buffer-file-name) (if (file-newer-than-file-p compiled-file-name buffer-file-name)
...@@ -219,7 +221,7 @@ All commands in `shared-lisp-mode-map' are inherited by this map.") ...@@ -219,7 +221,7 @@ All commands in `shared-lisp-mode-map' are inherited by this map.")
(defcustom emacs-lisp-mode-hook nil (defcustom emacs-lisp-mode-hook nil
"Hook run when entering Emacs Lisp mode." "Hook run when entering Emacs Lisp mode."
:options '(turn-on-eldoc-mode imenu-add-menubar-index) :options '(turn-on-eldoc-mode imenu-add-menubar-index checkdoc-minor-mode)
:type 'hook :type 'hook
:group 'lisp) :group 'lisp)
...@@ -253,17 +255,15 @@ if that value is non-nil." ...@@ -253,17 +255,15 @@ if that value is non-nil."
(setq imenu-case-fold-search nil) (setq imenu-case-fold-search nil)
(run-hooks 'emacs-lisp-mode-hook)) (run-hooks 'emacs-lisp-mode-hook))
(defvar lisp-mode-map () (defvar lisp-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map shared-lisp-mode-map)
(define-key map "\e\C-x" 'lisp-eval-defun)
(define-key map "\C-c\C-z" 'run-lisp)
map)
"Keymap for ordinary Lisp mode. "Keymap for ordinary Lisp mode.
All commands in `shared-lisp-mode-map' are inherited by this map.") All commands in `shared-lisp-mode-map' are inherited by this map.")
(if lisp-mode-map
()
(setq lisp-mode-map (make-sparse-keymap))
(set-keymap-parent lisp-mode-map shared-lisp-mode-map)
(define-key lisp-mode-map "\e\C-x" 'lisp-eval-defun)
(define-key lisp-mode-map "\C-c\C-z" 'run-lisp))
(defun lisp-mode () (defun lisp-mode ()
"Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp. "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.
Commands: Commands:
...@@ -291,18 +291,16 @@ if that value is non-nil." ...@@ -291,18 +291,16 @@ if that value is non-nil."
(interactive) (interactive)
(error "Process lisp does not exist")) (error "Process lisp does not exist"))
(defvar lisp-interaction-mode-map () (defvar lisp-interaction-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map shared-lisp-mode-map)
(define-key map "\e\C-x" 'eval-defun)
(define-key map "\e\t" 'lisp-complete-symbol)
(define-key map "\n" 'eval-print-last-sexp)
map)
"Keymap for Lisp Interaction mode. "Keymap for Lisp Interaction mode.
All commands in `shared-lisp-mode-map' are inherited by this map.") All commands in `shared-lisp-mode-map' are inherited by this map.")
(if lisp-interaction-mode-map
()
(setq lisp-interaction-mode-map (make-sparse-keymap))
(set-keymap-parent lisp-interaction-mode-map shared-lisp-mode-map)
(define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun)
(define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol)
(define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp))
(defun lisp-interaction-mode () (defun lisp-interaction-mode ()
"Major mode for typing and evaluating Lisp forms. "Major mode for typing and evaluating Lisp forms.
Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression
...@@ -404,10 +402,11 @@ With argument, print output into current buffer." ...@@ -404,10 +402,11 @@ With argument, print output into current buffer."
(cdr-safe (cdr-safe form))) (cdr-safe (cdr-safe form)))
;; Force variable to be bound. ;; Force variable to be bound.
(cons 'defconst (cdr form))) (cons 'defconst (cdr form)))
((and (eq (car form) 'defcustom) ;; `defcustom' is now macroexpanded to `custom-declare-variable'.
(default-boundp (nth 1 form))) ((and (eq (car form) 'custom-declare-variable)
(default-boundp (eval (nth 1 form))))
;; Force variable to be bound. ;; Force variable to be bound.
(set-default (nth 1 form) (eval (nth 2 form))) (set-default (eval (nth 1 form)) (eval (nth 2 form)))
form) form)
((eq (car form) 'progn) ((eq (car form) 'progn)
(cons 'progn (mapcar 'eval-defun-1 (cdr form)))) (cons 'progn (mapcar 'eval-defun-1 (cdr form))))
...@@ -499,8 +498,8 @@ Return the result of evaluation." ...@@ -499,8 +498,8 @@ Return the result of evaluation."
(let ((comment-start nil) (comment-start-skip nil)) (let ((comment-start nil) (comment-start-skip nil))
(do-auto-fill))))) (do-auto-fill)))))
(defvar lisp-indent-offset nil "") (defvar lisp-indent-offset nil)
(defvar lisp-indent-function 'lisp-indent-function "") (defvar lisp-indent-function 'lisp-indent-function)
(defun lisp-indent-line (&optional whole-exp) (defun lisp-indent-line (&optional whole-exp)
"Indent current line as Lisp code. "Indent current line as Lisp code.
...@@ -616,7 +615,7 @@ is the buffer position of the start of the containing expression." ...@@ -616,7 +615,7 @@ is the buffer position of the start of the containing expression."
(backward-prefix-chars)) (backward-prefix-chars))
(t (t
;; Indent beneath first sexp on same line as ;; Indent beneath first sexp on same line as
;; calculate-lisp-indent-last-sexp. Again, it's ;; `calculate-lisp-indent-last-sexp'. Again, it's
;; almost certainly a function call. ;; almost certainly a function call.
(goto-char calculate-lisp-indent-last-sexp) (goto-char calculate-lisp-indent-last-sexp)
(beginning-of-line) (beginning-of-line)
...@@ -869,8 +868,8 @@ ENDPOS is encountered." ...@@ -869,8 +868,8 @@ ENDPOS is encountered."
(setq outer-loop-done (= (point) last-point)) (setq outer-loop-done (= (point) last-point))
(setq last-point (point))))))) (setq last-point (point)))))))
;; Indent every line whose first char is between START and END inclusive.
(defun lisp-indent-region (start end) (defun lisp-indent-region (start end)
"Indent every line whose first char is between START and END inclusive."
(save-excursion (save-excursion
(let ((endmark (copy-marker end))) (let ((endmark (copy-marker end)))
(goto-char start) (goto-char start)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment