2013-10-07 05:11:50 +00:00
|
|
|
|
;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands -*- lexical-binding:t -*-
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
2016-01-01 09:16:19 +00:00
|
|
|
|
;; Copyright (C) 1985-1986, 1999-2016 Free Software Foundation, Inc.
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
2014-02-10 01:34:22 +00:00
|
|
|
|
;; Maintainer: emacs-devel@gnu.org
|
2008-09-23 17:59:28 +00:00
|
|
|
|
;; Keywords: lisp, languages
|
2010-08-29 16:17:13 +00:00
|
|
|
|
;; Package: emacs
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; The base major mode for editing Lisp code (used also for Emacs Lisp).
|
|
|
|
|
;; This mode is documented in the Emacs manual.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2015-09-24 12:54:39 +00:00
|
|
|
|
(eval-when-compile (require 'cl-lib))
|
|
|
|
|
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(defvar font-lock-comment-face)
|
|
|
|
|
(defvar font-lock-doc-face)
|
|
|
|
|
(defvar font-lock-keywords-case-fold-search)
|
|
|
|
|
(defvar font-lock-string-face)
|
|
|
|
|
|
2012-01-29 04:45:51 +00:00
|
|
|
|
(define-abbrev-table 'lisp-mode-abbrev-table ()
|
|
|
|
|
"Abbrev table for Lisp mode.")
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
(defvar lisp--mode-syntax-table
|
2011-06-28 12:09:43 +00:00
|
|
|
|
(let ((table (make-syntax-table))
|
|
|
|
|
(i 0))
|
|
|
|
|
(while (< i ?0)
|
|
|
|
|
(modify-syntax-entry i "_ " table)
|
|
|
|
|
(setq i (1+ i)))
|
|
|
|
|
(setq i (1+ ?9))
|
|
|
|
|
(while (< i ?A)
|
|
|
|
|
(modify-syntax-entry i "_ " table)
|
|
|
|
|
(setq i (1+ i)))
|
|
|
|
|
(setq i (1+ ?Z))
|
|
|
|
|
(while (< i ?a)
|
|
|
|
|
(modify-syntax-entry i "_ " table)
|
|
|
|
|
(setq i (1+ i)))
|
|
|
|
|
(setq i (1+ ?z))
|
|
|
|
|
(while (< i 128)
|
|
|
|
|
(modify-syntax-entry i "_ " table)
|
|
|
|
|
(setq i (1+ i)))
|
|
|
|
|
(modify-syntax-entry ?\s " " table)
|
|
|
|
|
;; Non-break space acts as whitespace.
|
|
|
|
|
(modify-syntax-entry ?\x8a0 " " table)
|
|
|
|
|
(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)
|
|
|
|
|
(modify-syntax-entry ?\; "< " table)
|
|
|
|
|
(modify-syntax-entry ?` "' " table)
|
|
|
|
|
(modify-syntax-entry ?' "' " table)
|
|
|
|
|
(modify-syntax-entry ?, "' " table)
|
2014-04-24 00:55:18 +00:00
|
|
|
|
(modify-syntax-entry ?@ "_ p" table)
|
2011-06-28 12:09:43 +00:00
|
|
|
|
;; Used to be singlequote; changed for flonums.
|
|
|
|
|
(modify-syntax-entry ?. "_ " table)
|
|
|
|
|
(modify-syntax-entry ?# "' " table)
|
|
|
|
|
(modify-syntax-entry ?\" "\" " table)
|
|
|
|
|
(modify-syntax-entry ?\\ "\\ " table)
|
|
|
|
|
(modify-syntax-entry ?\( "() " table)
|
|
|
|
|
(modify-syntax-entry ?\) ")( " table)
|
2009-09-17 06:26:59 +00:00
|
|
|
|
table)
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
"Parent syntax table used in Lisp modes.")
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
|
|
|
|
(defvar lisp-mode-syntax-table
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
(let ((table (make-syntax-table lisp--mode-syntax-table)))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(modify-syntax-entry ?\[ "_ " table)
|
|
|
|
|
(modify-syntax-entry ?\] "_ " table)
|
2010-08-12 14:44:16 +00:00
|
|
|
|
(modify-syntax-entry ?# "' 14" table)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(modify-syntax-entry ?| "\" 23bn" table)
|
2009-09-17 06:28:32 +00:00
|
|
|
|
table)
|
|
|
|
|
"Syntax table used in `lisp-mode'.")
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(eval-and-compile
|
|
|
|
|
(defconst lisp-mode-symbol-regexp "\\(?:\\sw\\|\\s_\\|\\\\.\\)+"))
|
|
|
|
|
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(defvar lisp-imenu-generic-expression
|
|
|
|
|
(list
|
|
|
|
|
(list nil
|
|
|
|
|
(purecopy (concat "^\\s-*("
|
|
|
|
|
(eval-when-compile
|
|
|
|
|
(regexp-opt
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
'("defun" "defmacro"
|
|
|
|
|
;; Elisp.
|
2015-07-07 06:14:16 +00:00
|
|
|
|
"defun*" "defsubst" "define-inline"
|
2014-11-18 15:57:01 +00:00
|
|
|
|
"define-advice" "defadvice" "define-skeleton"
|
2014-04-05 02:33:36 +00:00
|
|
|
|
"define-compilation-mode" "define-minor-mode"
|
|
|
|
|
"define-global-minor-mode"
|
2008-09-23 17:59:28 +00:00
|
|
|
|
"define-globalized-minor-mode"
|
|
|
|
|
"define-derived-mode" "define-generic-mode"
|
2015-12-26 20:44:11 +00:00
|
|
|
|
"ert-deftest"
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
"cl-defun" "cl-defsubst" "cl-defmacro"
|
2015-12-22 23:53:05 +00:00
|
|
|
|
"cl-define-compiler-macro" "cl-defgeneric"
|
|
|
|
|
"cl-defmethod"
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
;; CL.
|
2008-09-23 17:59:28 +00:00
|
|
|
|
"define-compiler-macro" "define-modify-macro"
|
|
|
|
|
"defsetf" "define-setf-expander"
|
|
|
|
|
"define-method-combination"
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
;; CLOS and EIEIO
|
|
|
|
|
"defgeneric" "defmethod")
|
|
|
|
|
t))
|
2015-09-15 16:44:35 +00:00
|
|
|
|
"\\s-+\\(" lisp-mode-symbol-regexp "\\)"))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
2)
|
|
|
|
|
(list (purecopy "Variables")
|
|
|
|
|
(purecopy (concat "^\\s-*("
|
|
|
|
|
(eval-when-compile
|
|
|
|
|
(regexp-opt
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
'(;; Elisp
|
|
|
|
|
"defconst" "defcustom"
|
|
|
|
|
;; CL
|
|
|
|
|
"defconstant"
|
|
|
|
|
"defparameter" "define-symbol-macro")
|
|
|
|
|
t))
|
2015-09-15 16:44:35 +00:00
|
|
|
|
"\\s-+\\(" lisp-mode-symbol-regexp "\\)"))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
2)
|
2016-01-07 03:00:52 +00:00
|
|
|
|
;; For `defvar'/`defvar-local', we ignore (defvar FOO) constructs.
|
2012-08-05 14:14:54 +00:00
|
|
|
|
(list (purecopy "Variables")
|
2016-01-07 03:00:52 +00:00
|
|
|
|
(purecopy (concat "^\\s-*(defvar\\(?:-local\\)?\\s-+\\("
|
|
|
|
|
lisp-mode-symbol-regexp "\\)"
|
2012-08-05 14:14:54 +00:00
|
|
|
|
"[[:space:]\n]+[^)]"))
|
|
|
|
|
1)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(list (purecopy "Types")
|
|
|
|
|
(purecopy (concat "^\\s-*("
|
|
|
|
|
(eval-when-compile
|
|
|
|
|
(regexp-opt
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
'(;; Elisp
|
|
|
|
|
"defgroup" "deftheme"
|
|
|
|
|
"define-widget" "define-error"
|
|
|
|
|
"defface" "cl-deftype" "cl-defstruct"
|
|
|
|
|
;; CL
|
|
|
|
|
"deftype" "defstruct"
|
|
|
|
|
"define-condition" "defpackage"
|
|
|
|
|
;; CLOS and EIEIO
|
|
|
|
|
"defclass")
|
|
|
|
|
t))
|
2015-09-15 16:44:35 +00:00
|
|
|
|
"\\s-+'?\\(" lisp-mode-symbol-regexp "\\)"))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
2))
|
|
|
|
|
|
|
|
|
|
"Imenu generic expression for Lisp mode. See `imenu-generic-expression'.")
|
|
|
|
|
|
|
|
|
|
;; This was originally in autoload.el and is still used there.
|
|
|
|
|
(put 'autoload 'doc-string-elt 3)
|
2011-12-08 13:23:43 +00:00
|
|
|
|
(put 'defmethod 'doc-string-elt 3)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(put 'defvar 'doc-string-elt 3)
|
|
|
|
|
(put 'defconst 'doc-string-elt 3)
|
|
|
|
|
(put 'defalias 'doc-string-elt 3)
|
|
|
|
|
(put 'defvaralias 'doc-string-elt 3)
|
|
|
|
|
(put 'define-category 'doc-string-elt 2)
|
|
|
|
|
|
|
|
|
|
(defvar lisp-doc-string-elt-property 'doc-string-elt
|
|
|
|
|
"The symbol property that holds the docstring position info.")
|
|
|
|
|
|
2013-10-08 14:57:18 +00:00
|
|
|
|
|
|
|
|
|
;;;; Font-lock support.
|
|
|
|
|
|
2014-04-22 17:45:43 +00:00
|
|
|
|
(defun lisp--match-hidden-arg (limit)
|
|
|
|
|
(let ((res nil))
|
|
|
|
|
(while
|
|
|
|
|
(let ((ppss (parse-partial-sexp (line-beginning-position)
|
|
|
|
|
(line-end-position)
|
|
|
|
|
-1)))
|
2014-05-01 16:14:03 +00:00
|
|
|
|
(skip-syntax-forward " )")
|
2014-04-22 17:45:43 +00:00
|
|
|
|
(if (or (>= (car ppss) 0)
|
2014-05-01 16:14:03 +00:00
|
|
|
|
(looking-at ";\\|$"))
|
2014-04-22 17:45:43 +00:00
|
|
|
|
(progn
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(< (point) limit))
|
|
|
|
|
(looking-at ".*") ;Set the match-data.
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(setq res (point))
|
|
|
|
|
nil)))
|
|
|
|
|
res))
|
|
|
|
|
|
2015-04-15 20:39:18 +00:00
|
|
|
|
(defun lisp--el-non-funcall-position-p (pos)
|
2015-03-23 08:38:12 +00:00
|
|
|
|
"Heuristically determine whether POS is an evaluated position."
|
|
|
|
|
(save-match-data
|
|
|
|
|
(save-excursion
|
2015-03-23 08:42:56 +00:00
|
|
|
|
(ignore-errors
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(or (eql (char-before) ?\')
|
2015-04-15 20:39:18 +00:00
|
|
|
|
(let* ((ppss (syntax-ppss))
|
|
|
|
|
(paren-posns (nth 9 ppss))
|
|
|
|
|
(parent
|
|
|
|
|
(when paren-posns
|
|
|
|
|
(goto-char (car (last paren-posns))) ;(up-list -1)
|
|
|
|
|
(cond
|
2015-03-23 08:50:42 +00:00
|
|
|
|
((ignore-errors
|
|
|
|
|
(and (eql (char-after) ?\()
|
2015-04-15 20:39:18 +00:00
|
|
|
|
(when (cdr paren-posns)
|
|
|
|
|
(goto-char (car (last paren-posns 2)))
|
2015-03-23 08:50:42 +00:00
|
|
|
|
(looking-at "(\\_<let\\*?\\_>"))))
|
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
'let)
|
|
|
|
|
((looking-at
|
|
|
|
|
(rx "("
|
|
|
|
|
(group-n 1 (+ (or (syntax w) (syntax _))))
|
|
|
|
|
symbol-end))
|
|
|
|
|
(prog1 (intern-soft (match-string-no-properties 1))
|
|
|
|
|
(goto-char (match-end 1))))))))
|
2015-03-23 08:42:56 +00:00
|
|
|
|
(or (eq parent 'declare)
|
|
|
|
|
(and (eq parent 'let)
|
|
|
|
|
(progn
|
|
|
|
|
(forward-sexp 1)
|
|
|
|
|
(< pos (point))))
|
|
|
|
|
(and (eq parent 'condition-case)
|
|
|
|
|
(progn
|
|
|
|
|
(forward-sexp 2)
|
|
|
|
|
(< (point) pos))))))))))
|
2015-03-23 08:38:12 +00:00
|
|
|
|
|
2015-03-16 09:25:14 +00:00
|
|
|
|
(defun lisp--el-match-keyword (limit)
|
2015-04-15 20:50:17 +00:00
|
|
|
|
;; FIXME: Move to elisp-mode.el.
|
2015-03-16 09:25:14 +00:00
|
|
|
|
(catch 'found
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(while (re-search-forward
|
2015-09-16 07:02:35 +00:00
|
|
|
|
(eval-when-compile
|
|
|
|
|
(concat "(\\(" lisp-mode-symbol-regexp "\\)\\_>"))
|
2015-09-15 16:44:35 +00:00
|
|
|
|
limit t)
|
2015-03-16 09:25:14 +00:00
|
|
|
|
(let ((sym (intern-soft (match-string 1))))
|
|
|
|
|
(when (or (special-form-p sym)
|
|
|
|
|
(and (macrop sym)
|
2015-03-23 08:38:12 +00:00
|
|
|
|
(not (get sym 'no-font-lock-keyword))
|
|
|
|
|
(not (lisp--el-non-funcall-position-p
|
|
|
|
|
(match-beginning 0)))))
|
2015-03-16 09:25:14 +00:00
|
|
|
|
(throw 'found t))))))
|
|
|
|
|
|
2015-09-23 11:50:15 +00:00
|
|
|
|
(defmacro let-when-compile (bindings &rest body)
|
2015-09-29 19:08:55 +00:00
|
|
|
|
"Like `let*', but allow for compile time optimization.
|
|
|
|
|
Use BINDINGS as in regular `let*', but in BODY each usage should
|
2015-09-23 11:50:15 +00:00
|
|
|
|
be wrapped in `eval-when-compile'.
|
|
|
|
|
This will generate compile-time constants from BINDINGS."
|
|
|
|
|
(declare (indent 1) (debug let))
|
2015-09-29 19:08:55 +00:00
|
|
|
|
(letrec ((loop
|
|
|
|
|
(lambda (bindings)
|
|
|
|
|
(if (null bindings)
|
|
|
|
|
(macroexpand-all (macroexp-progn body)
|
|
|
|
|
macroexpand-all-environment)
|
|
|
|
|
(let ((binding (pop bindings)))
|
|
|
|
|
(cl-progv (list (car binding))
|
|
|
|
|
(list (eval (nth 1 binding) t))
|
|
|
|
|
(funcall loop bindings)))))))
|
|
|
|
|
(funcall loop bindings)))
|
2015-09-23 11:50:15 +00:00
|
|
|
|
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(let-when-compile
|
2015-07-07 06:14:16 +00:00
|
|
|
|
((lisp-fdefs '("defmacro" "defun"))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(lisp-vdefs '("defvar"))
|
|
|
|
|
(lisp-kw '("cond" "if" "while" "let" "let*" "progn" "prog1"
|
|
|
|
|
"prog2" "lambda" "unwind-protect" "condition-case"
|
|
|
|
|
"when" "unless" "with-output-to-string"
|
|
|
|
|
"ignore-errors" "dotimes" "dolist" "declare"))
|
|
|
|
|
(lisp-errs '("warn" "error" "signal"))
|
|
|
|
|
;; Elisp constructs. Now they are update dynamically
|
|
|
|
|
;; from obarray but they are also used for setting up
|
|
|
|
|
;; the keywords for Common Lisp.
|
2015-07-07 06:14:16 +00:00
|
|
|
|
(el-fdefs '("defsubst" "cl-defsubst" "define-inline"
|
|
|
|
|
"define-advice" "defadvice" "defalias"
|
2015-05-19 07:49:12 +00:00
|
|
|
|
"define-derived-mode" "define-minor-mode"
|
|
|
|
|
"define-generic-mode" "define-global-minor-mode"
|
|
|
|
|
"define-globalized-minor-mode" "define-skeleton"
|
2015-12-26 20:44:11 +00:00
|
|
|
|
"define-widget" "ert-deftest"))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(el-vdefs '("defconst" "defcustom" "defvaralias" "defvar-local"
|
|
|
|
|
"defface"))
|
|
|
|
|
(el-tdefs '("defgroup" "deftheme"))
|
|
|
|
|
(el-errs '("user-error"))
|
|
|
|
|
;; Common-Lisp constructs supported by EIEIO. FIXME: namespace.
|
|
|
|
|
(eieio-fdefs '("defgeneric" "defmethod"))
|
|
|
|
|
(eieio-tdefs '("defclass"))
|
|
|
|
|
;; Common-Lisp constructs supported by cl-lib.
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(cl-lib-fdefs '("defmacro" "defsubst" "defun" "defmethod" "defgeneric"))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(cl-lib-tdefs '("defstruct" "deftype"))
|
|
|
|
|
(cl-lib-errs '("assert" "check-type"))
|
|
|
|
|
;; Common-Lisp constructs not supported by cl-lib.
|
|
|
|
|
(cl-fdefs '("defsetf" "define-method-combination"
|
|
|
|
|
"define-condition" "define-setf-expander"
|
|
|
|
|
;; "define-function"??
|
|
|
|
|
"define-compiler-macro" "define-modify-macro"))
|
|
|
|
|
(cl-vdefs '("define-symbol-macro" "defconstant" "defparameter"))
|
|
|
|
|
(cl-tdefs '("defpackage" "defstruct" "deftype"))
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(cl-kw '("block" "break" "case" "ccase" "compiler-let" "ctypecase"
|
|
|
|
|
"declaim" "destructuring-bind" "do" "do*"
|
|
|
|
|
"ecase" "etypecase" "eval-when" "flet" "flet*"
|
|
|
|
|
"go" "handler-case" "handler-bind" "in-package" ;; "inline"
|
|
|
|
|
"labels" "letf" "locally" "loop"
|
|
|
|
|
"macrolet" "multiple-value-bind" "multiple-value-prog1"
|
|
|
|
|
"proclaim" "prog" "prog*" "progv"
|
|
|
|
|
"restart-case" "restart-bind" "return" "return-from"
|
|
|
|
|
"symbol-macrolet" "tagbody" "the" "typecase"
|
|
|
|
|
"with-accessors" "with-compilation-unit"
|
2015-05-19 07:49:12 +00:00
|
|
|
|
"with-condition-restarts" "with-hash-table-iterator"
|
|
|
|
|
"with-input-from-string" "with-open-file"
|
|
|
|
|
"with-open-stream" "with-package-iterator"
|
2015-09-15 16:44:35 +00:00
|
|
|
|
"with-simple-restart" "with-slots" "with-standard-io-syntax"))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(cl-errs '("abort" "cerror")))
|
|
|
|
|
(let ((vdefs (eval-when-compile
|
|
|
|
|
(append lisp-vdefs el-vdefs cl-vdefs)))
|
|
|
|
|
(tdefs (eval-when-compile
|
|
|
|
|
(append el-tdefs eieio-tdefs cl-tdefs cl-lib-tdefs
|
|
|
|
|
(mapcar (lambda (s) (concat "cl-" s)) cl-lib-tdefs))))
|
|
|
|
|
;; Elisp and Common Lisp definers.
|
|
|
|
|
(el-defs-re (eval-when-compile
|
|
|
|
|
(regexp-opt (append lisp-fdefs lisp-vdefs
|
|
|
|
|
el-fdefs el-vdefs el-tdefs
|
|
|
|
|
(mapcar (lambda (s) (concat "cl-" s))
|
|
|
|
|
(append cl-lib-fdefs cl-lib-tdefs))
|
|
|
|
|
eieio-fdefs eieio-tdefs)
|
|
|
|
|
t)))
|
|
|
|
|
(cl-defs-re (eval-when-compile
|
|
|
|
|
(regexp-opt (append lisp-fdefs lisp-vdefs
|
|
|
|
|
cl-lib-fdefs cl-lib-tdefs
|
|
|
|
|
eieio-fdefs eieio-tdefs
|
|
|
|
|
cl-fdefs cl-vdefs cl-tdefs)
|
|
|
|
|
t)))
|
2015-09-15 16:44:35 +00:00
|
|
|
|
;; Common Lisp keywords (Elisp keywords are handled dynamically).
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(cl-kws-re (eval-when-compile
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(regexp-opt (append lisp-kw cl-kw) t)))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
;; Elisp and Common Lisp "errors".
|
|
|
|
|
(el-errs-re (eval-when-compile
|
|
|
|
|
(regexp-opt (append (mapcar (lambda (s) (concat "cl-" s))
|
|
|
|
|
cl-lib-errs)
|
|
|
|
|
lisp-errs el-errs)
|
|
|
|
|
t)))
|
|
|
|
|
(cl-errs-re (eval-when-compile
|
|
|
|
|
(regexp-opt (append lisp-errs cl-lib-errs cl-errs) t))))
|
|
|
|
|
(dolist (v vdefs)
|
|
|
|
|
(put (intern v) 'lisp-define-type 'var))
|
|
|
|
|
(dolist (v tdefs)
|
|
|
|
|
(put (intern v) 'lisp-define-type 'type))
|
|
|
|
|
|
|
|
|
|
(define-obsolete-variable-alias 'lisp-font-lock-keywords-1
|
|
|
|
|
'lisp-el-font-lock-keywords-1 "24.4")
|
|
|
|
|
(defconst lisp-el-font-lock-keywords-1
|
|
|
|
|
`( ;; Definitions.
|
|
|
|
|
(,(concat "(" el-defs-re "\\_>"
|
|
|
|
|
;; Any whitespace and defined object.
|
|
|
|
|
"[ \t']*"
|
|
|
|
|
"\\(([ \t']*\\)?" ;; An opening paren.
|
2015-09-15 16:44:35 +00:00
|
|
|
|
"\\(\\(setf\\)[ \t]+" lisp-mode-symbol-regexp
|
|
|
|
|
"\\|" lisp-mode-symbol-regexp "\\)?")
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(1 font-lock-keyword-face)
|
|
|
|
|
(3 (let ((type (get (intern-soft (match-string 1)) 'lisp-define-type)))
|
|
|
|
|
(cond ((eq type 'var) font-lock-variable-name-face)
|
|
|
|
|
((eq type 'type) font-lock-type-face)
|
|
|
|
|
;; If match-string 2 is non-nil, we encountered a
|
|
|
|
|
;; form like (defalias (intern (concat s "-p"))),
|
|
|
|
|
;; unless match-string 4 is also there. Then its a
|
|
|
|
|
;; defmethod with (setf foo) as name.
|
|
|
|
|
((or (not (match-string 2)) ;; Normal defun.
|
|
|
|
|
(and (match-string 2) ;; Setf method.
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(match-string 4)))
|
|
|
|
|
font-lock-function-name-face)))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
nil t))
|
|
|
|
|
;; Emacs Lisp autoload cookies. Supports the slightly different
|
|
|
|
|
;; forms used by mh-e, calendar, etc.
|
|
|
|
|
("^;;;###\\([-a-z]*autoload\\)" 1 font-lock-warning-face prepend))
|
|
|
|
|
"Subdued level highlighting for Emacs Lisp mode.")
|
|
|
|
|
|
|
|
|
|
(defconst lisp-cl-font-lock-keywords-1
|
|
|
|
|
`( ;; Definitions.
|
|
|
|
|
(,(concat "(" cl-defs-re "\\_>"
|
|
|
|
|
;; Any whitespace and defined object.
|
|
|
|
|
"[ \t']*"
|
|
|
|
|
"\\(([ \t']*\\)?" ;; An opening paren.
|
2015-09-15 16:44:35 +00:00
|
|
|
|
"\\(\\(setf\\)[ \t]+" lisp-mode-symbol-regexp
|
|
|
|
|
"\\|" lisp-mode-symbol-regexp "\\)?")
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(1 font-lock-keyword-face)
|
|
|
|
|
(3 (let ((type (get (intern-soft (match-string 1)) 'lisp-define-type)))
|
|
|
|
|
(cond ((eq type 'var) font-lock-variable-name-face)
|
|
|
|
|
((eq type 'type) font-lock-type-face)
|
|
|
|
|
((or (not (match-string 2)) ;; Normal defun.
|
|
|
|
|
(and (match-string 2) ;; Setf function.
|
2016-01-02 07:48:44 +00:00
|
|
|
|
(match-string 4)))
|
|
|
|
|
font-lock-function-name-face)))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
nil t)))
|
|
|
|
|
"Subdued level highlighting for Lisp modes.")
|
|
|
|
|
|
|
|
|
|
(define-obsolete-variable-alias 'lisp-font-lock-keywords-2
|
|
|
|
|
'lisp-el-font-lock-keywords-2 "24.4")
|
|
|
|
|
(defconst lisp-el-font-lock-keywords-2
|
|
|
|
|
(append
|
|
|
|
|
lisp-el-font-lock-keywords-1
|
|
|
|
|
`( ;; Regexp negated char group.
|
|
|
|
|
("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)
|
2016-04-11 12:19:38 +00:00
|
|
|
|
;; Erroneous structures.
|
|
|
|
|
(,(concat "(" el-errs-re "\\_>")
|
|
|
|
|
(1 font-lock-warning-face))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
;; Control structures. Common Lisp forms.
|
|
|
|
|
(lisp--el-match-keyword . 1)
|
|
|
|
|
;; Exit/Feature symbols as constants.
|
|
|
|
|
(,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\_>"
|
2015-09-15 16:44:35 +00:00
|
|
|
|
"[ \t']*\\(" lisp-mode-symbol-regexp "\\)?")
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(1 font-lock-keyword-face)
|
|
|
|
|
(2 font-lock-constant-face nil t))
|
|
|
|
|
;; Words inside \\[] tend to be for `substitute-command-keys'.
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(,(concat "\\\\\\\\\\[\\(" lisp-mode-symbol-regexp "\\)\\]")
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(1 font-lock-constant-face prepend))
|
2016-03-06 00:40:49 +00:00
|
|
|
|
;; Words inside ‘’ and `' tend to be symbol names.
|
|
|
|
|
(,(concat "[`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)"
|
2015-09-15 16:44:35 +00:00
|
|
|
|
lisp-mode-symbol-regexp "\\)['’]")
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(1 font-lock-constant-face prepend))
|
|
|
|
|
;; Constant values.
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(,(concat "\\_<:" lisp-mode-symbol-regexp "\\_>")
|
|
|
|
|
(0 font-lock-builtin-face))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
;; ELisp and CLisp `&' keywords as types.
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(,(concat "\\_<\\&" lisp-mode-symbol-regexp "\\_>")
|
|
|
|
|
. font-lock-type-face)
|
2015-05-19 07:49:12 +00:00
|
|
|
|
;; ELisp regexp grouping constructs
|
|
|
|
|
(,(lambda (bound)
|
|
|
|
|
(catch 'found
|
|
|
|
|
;; The following loop is needed to continue searching after matches
|
|
|
|
|
;; that do not occur in strings. The associated regexp matches one
|
|
|
|
|
;; of `\\\\' `\\(' `\\(?:' `\\|' `\\)'. `\\\\' has been included to
|
|
|
|
|
;; avoid highlighting, for example, `\\(' in `\\\\('.
|
|
|
|
|
(while (re-search-forward "\\(\\\\\\\\\\)\\(?:\\(\\\\\\\\\\)\\|\\((\\(?:\\?[0-9]*:\\)?\\|[|)]\\)\\)" bound t)
|
|
|
|
|
(unless (match-beginning 2)
|
|
|
|
|
(let ((face (get-text-property (1- (point)) 'face)))
|
|
|
|
|
(when (or (and (listp face)
|
|
|
|
|
(memq 'font-lock-string-face face))
|
|
|
|
|
(eq 'font-lock-string-face face))
|
|
|
|
|
(throw 'found t)))))))
|
|
|
|
|
(1 'font-lock-regexp-grouping-backslash prepend)
|
|
|
|
|
(3 'font-lock-regexp-grouping-construct prepend))
|
|
|
|
|
;; This is too general -- rms.
|
|
|
|
|
;; A user complained that he has functions whose names start with `do'
|
|
|
|
|
;; and that they get the wrong color.
|
|
|
|
|
;; ;; CL `with-' and `do-' constructs
|
|
|
|
|
;;("(\\(\\(do-\\|with-\\)\\(\\s_\\|\\w\\)*\\)" 1 font-lock-keyword-face)
|
|
|
|
|
(lisp--match-hidden-arg
|
|
|
|
|
(0 '(face font-lock-warning-face
|
|
|
|
|
help-echo "Hidden behind deeper element; move to another line?")))
|
|
|
|
|
))
|
|
|
|
|
"Gaudy level highlighting for Emacs Lisp mode.")
|
|
|
|
|
|
|
|
|
|
(defconst lisp-cl-font-lock-keywords-2
|
|
|
|
|
(append
|
|
|
|
|
lisp-cl-font-lock-keywords-1
|
|
|
|
|
`( ;; Regexp negated char group.
|
|
|
|
|
("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)
|
|
|
|
|
;; Control structures. Common Lisp forms.
|
|
|
|
|
(,(concat "(" cl-kws-re "\\_>") . 1)
|
|
|
|
|
;; Exit/Feature symbols as constants.
|
|
|
|
|
(,(concat "(\\(catch\\|throw\\|provide\\|require\\)\\_>"
|
2015-09-15 16:44:35 +00:00
|
|
|
|
"[ \t']*\\(" lisp-mode-symbol-regexp "\\)?")
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(1 font-lock-keyword-face)
|
|
|
|
|
(2 font-lock-constant-face nil t))
|
|
|
|
|
;; Erroneous structures.
|
|
|
|
|
(,(concat "(" cl-errs-re "\\_>")
|
|
|
|
|
(1 font-lock-warning-face))
|
2016-03-06 00:40:49 +00:00
|
|
|
|
;; Words inside ‘’ and `' tend to be symbol names.
|
|
|
|
|
(,(concat "[`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)"
|
2015-09-15 16:44:35 +00:00
|
|
|
|
lisp-mode-symbol-regexp "\\)['’]")
|
2015-05-19 07:49:12 +00:00
|
|
|
|
(1 font-lock-constant-face prepend))
|
|
|
|
|
;; Constant values.
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(,(concat "\\_<:" lisp-mode-symbol-regexp "\\_>")
|
|
|
|
|
(0 font-lock-builtin-face))
|
2015-05-19 07:49:12 +00:00
|
|
|
|
;; ELisp and CLisp `&' keywords as types.
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(,(concat "\\_<\\&" lisp-mode-symbol-regexp "\\_>")
|
|
|
|
|
. font-lock-type-face)
|
2015-05-19 07:49:12 +00:00
|
|
|
|
;; This is too general -- rms.
|
|
|
|
|
;; A user complained that he has functions whose names start with `do'
|
|
|
|
|
;; and that they get the wrong color.
|
|
|
|
|
;; ;; CL `with-' and `do-' constructs
|
|
|
|
|
;;("(\\(\\(do-\\|with-\\)\\(\\s_\\|\\w\\)*\\)" 1 font-lock-keyword-face)
|
|
|
|
|
(lisp--match-hidden-arg
|
|
|
|
|
(0 '(face font-lock-warning-face
|
|
|
|
|
help-echo "Hidden behind deeper element; move to another line?")))
|
|
|
|
|
))
|
|
|
|
|
"Gaudy level highlighting for Lisp modes.")))
|
2013-10-08 14:57:18 +00:00
|
|
|
|
|
|
|
|
|
(define-obsolete-variable-alias 'lisp-font-lock-keywords
|
|
|
|
|
'lisp-el-font-lock-keywords "24.4")
|
|
|
|
|
(defvar lisp-el-font-lock-keywords lisp-el-font-lock-keywords-1
|
|
|
|
|
"Default expressions to highlight in Emacs Lisp mode.")
|
|
|
|
|
(defvar lisp-cl-font-lock-keywords lisp-cl-font-lock-keywords-1
|
|
|
|
|
"Default expressions to highlight in Lisp modes.")
|
|
|
|
|
|
2014-06-19 14:03:45 +00:00
|
|
|
|
(defun lisp-string-in-doc-position-p (listbeg startpos)
|
2015-12-30 17:59:12 +00:00
|
|
|
|
"Return true if a doc string may occur at STARTPOS inside a list.
|
|
|
|
|
LISTBEG is the position of the start of the innermost list
|
|
|
|
|
containing STARTPOS."
|
2014-06-19 14:03:45 +00:00
|
|
|
|
(let* ((firstsym (and listbeg
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char listbeg)
|
2015-09-15 16:44:35 +00:00
|
|
|
|
(and (looking-at
|
|
|
|
|
(eval-when-compile
|
|
|
|
|
(concat "([ \t\n]*\\("
|
|
|
|
|
lisp-mode-symbol-regexp "\\)")))
|
2014-06-19 14:03:45 +00:00
|
|
|
|
(match-string 1)))))
|
|
|
|
|
(docelt (and firstsym
|
|
|
|
|
(function-get (intern-soft firstsym)
|
|
|
|
|
lisp-doc-string-elt-property))))
|
|
|
|
|
(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) startpos))))))
|
|
|
|
|
|
|
|
|
|
(defun lisp-string-after-doc-keyword-p (listbeg startpos)
|
2015-12-30 17:59:12 +00:00
|
|
|
|
"Return true if `:documentation' symbol ends at STARTPOS inside a list.
|
|
|
|
|
LISTBEG is the position of the start of the innermost list
|
|
|
|
|
containing STARTPOS."
|
2014-06-19 14:03:45 +00:00
|
|
|
|
(and listbeg ; We are inside a Lisp form.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char startpos)
|
|
|
|
|
(ignore-errors
|
|
|
|
|
(progn (backward-sexp 1)
|
|
|
|
|
(looking-at ":documentation\\_>"))))))
|
|
|
|
|
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(defun lisp-font-lock-syntactic-face-function (state)
|
2015-12-30 17:59:12 +00:00
|
|
|
|
"Return syntactic face function for the position represented by STATE.
|
|
|
|
|
STATE is a `parse-partial-sexp' state, and the returned function is the
|
|
|
|
|
Lisp font lock syntactic face function."
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(if (nth 3 state)
|
|
|
|
|
;; 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
|
2014-06-19 14:03:45 +00:00
|
|
|
|
(let ((listbeg (nth 1 state)))
|
|
|
|
|
(if (or (lisp-string-in-doc-position-p listbeg startpos)
|
|
|
|
|
(lisp-string-after-doc-keyword-p listbeg startpos))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
font-lock-doc-face
|
|
|
|
|
font-lock-string-face))))
|
|
|
|
|
font-lock-comment-face))
|
|
|
|
|
|
2013-10-08 14:57:18 +00:00
|
|
|
|
(defun lisp-mode-variables (&optional lisp-syntax keywords-case-insensitive
|
|
|
|
|
elisp)
|
2008-11-07 06:30:17 +00:00
|
|
|
|
"Common initialization routine for lisp modes.
|
|
|
|
|
The LISP-SYNTAX argument is used by code in inf-lisp.el and is
|
2009-06-07 07:21:23 +00:00
|
|
|
|
\(uselessly) passed from pp.el, chistory.el, gnus-kill.el and
|
|
|
|
|
score-mode.el. KEYWORDS-CASE-INSENSITIVE non-nil means that for
|
2013-02-17 16:58:12 +00:00
|
|
|
|
font-lock keywords will not be case sensitive."
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(when lisp-syntax
|
|
|
|
|
(set-syntax-table lisp-mode-syntax-table))
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 04:09:55 +00:00
|
|
|
|
(setq-local paragraph-ignore-fill-prefix t)
|
|
|
|
|
(setq-local fill-paragraph-function 'lisp-fill-paragraph)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
;; Adaptive fill mode gets the fill wrong for a one-line paragraph made of
|
|
|
|
|
;; a single docstring. Let's fix it here.
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 04:09:55 +00:00
|
|
|
|
(setq-local adaptive-fill-function
|
|
|
|
|
(lambda () (if (looking-at "\\s-+\"[^\n\"]+\"\\s-*$") "")))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
;; Adaptive fill mode gets in the way of auto-fill,
|
|
|
|
|
;; and should make no difference for explicit fill
|
|
|
|
|
;; because lisp-fill-paragraph should do the job.
|
|
|
|
|
;; I believe that newcomment's auto-fill code properly deals with it -stef
|
|
|
|
|
;;(set (make-local-variable 'adaptive-fill-mode) nil)
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 04:09:55 +00:00
|
|
|
|
(setq-local indent-line-function 'lisp-indent-line)
|
|
|
|
|
(setq-local outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(")
|
|
|
|
|
(setq-local outline-level 'lisp-outline-level)
|
2012-12-01 04:57:07 +00:00
|
|
|
|
(setq-local add-log-current-defun-function #'lisp-current-defun-name)
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 04:09:55 +00:00
|
|
|
|
(setq-local comment-start ";")
|
2014-03-17 06:22:58 +00:00
|
|
|
|
(setq-local comment-start-skip ";+ *")
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 04:09:55 +00:00
|
|
|
|
(setq-local comment-add 1) ;default to `;;' in comment-region
|
|
|
|
|
(setq-local comment-column 40)
|
2014-03-17 06:22:58 +00:00
|
|
|
|
(setq-local comment-use-syntax t)
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 04:09:55 +00:00
|
|
|
|
(setq-local imenu-generic-expression lisp-imenu-generic-expression)
|
|
|
|
|
(setq-local multibyte-syntax-as-symbol t)
|
2014-01-03 22:38:55 +00:00
|
|
|
|
;; (setq-local syntax-begin-function 'beginning-of-defun) ;;Bug#16247.
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(setq font-lock-defaults
|
2013-10-08 14:57:18 +00:00
|
|
|
|
`(,(if elisp '(lisp-el-font-lock-keywords
|
|
|
|
|
lisp-el-font-lock-keywords-1
|
|
|
|
|
lisp-el-font-lock-keywords-2)
|
|
|
|
|
'(lisp-cl-font-lock-keywords
|
|
|
|
|
lisp-cl-font-lock-keywords-1
|
|
|
|
|
lisp-cl-font-lock-keywords-2))
|
2013-02-17 16:58:12 +00:00
|
|
|
|
nil ,keywords-case-insensitive nil nil
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(font-lock-mark-block-function . mark-defun)
|
2014-04-22 17:45:43 +00:00
|
|
|
|
(font-lock-extra-managed-props help-echo)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(font-lock-syntactic-face-function
|
2013-06-11 18:00:27 +00:00
|
|
|
|
. lisp-font-lock-syntactic-face-function)))
|
2013-12-26 22:02:49 +00:00
|
|
|
|
(setq-local prettify-symbols-alist lisp--prettify-symbols-alist)
|
|
|
|
|
(setq-local electric-pair-skip-whitespace 'chomp)
|
|
|
|
|
(setq-local electric-pair-open-newline-between-pairs nil))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
|
|
|
|
(defun lisp-outline-level ()
|
|
|
|
|
"Lisp mode `outline-level' function."
|
|
|
|
|
(let ((len (- (match-end 0) (match-beginning 0))))
|
|
|
|
|
(if (looking-at "(\\|;;;###autoload")
|
|
|
|
|
1000
|
|
|
|
|
len)))
|
|
|
|
|
|
2012-12-01 04:57:07 +00:00
|
|
|
|
(defun lisp-current-defun-name ()
|
|
|
|
|
"Return the name of the defun at point, or nil."
|
2012-12-01 05:09:12 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((location (point)))
|
|
|
|
|
;; If we are now precisely at the beginning of a defun, make sure
|
|
|
|
|
;; beginning-of-defun finds that one rather than the previous one.
|
|
|
|
|
(or (eobp) (forward-char 1))
|
|
|
|
|
(beginning-of-defun)
|
|
|
|
|
;; Make sure we are really inside the defun found, not after it.
|
|
|
|
|
(when (and (looking-at "\\s(")
|
|
|
|
|
(progn (end-of-defun)
|
|
|
|
|
(< location (point)))
|
|
|
|
|
(progn (forward-sexp -1)
|
|
|
|
|
(>= location (point))))
|
|
|
|
|
(if (looking-at "\\s(")
|
|
|
|
|
(forward-char 1))
|
|
|
|
|
;; Skip the defining construct name, typically "defun" or
|
|
|
|
|
;; "defvar".
|
|
|
|
|
(forward-sexp 1)
|
|
|
|
|
;; The second element is usually a symbol being defined. If it
|
|
|
|
|
;; is not, use the first symbol in it.
|
|
|
|
|
(skip-chars-forward " \t\n'(")
|
|
|
|
|
(buffer-substring-no-properties (point)
|
|
|
|
|
(progn (forward-sexp 1)
|
|
|
|
|
(point)))))))
|
2012-12-01 04:57:07 +00:00
|
|
|
|
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(defvar lisp-mode-shared-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
2013-05-29 14:14:16 +00:00
|
|
|
|
(set-keymap-parent map prog-mode-map)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(define-key map "\e\C-q" 'indent-sexp)
|
|
|
|
|
(define-key map "\177" 'backward-delete-char-untabify)
|
|
|
|
|
;; This gets in the way when viewing a Lisp file in view-mode. As
|
|
|
|
|
;; long as [backspace] is mapped into DEL via the
|
|
|
|
|
;; function-key-map, this should remain disabled!!
|
|
|
|
|
;;;(define-key map [backspace] 'backward-delete-char-untabify)
|
|
|
|
|
map)
|
|
|
|
|
"Keymap for commands shared by all sorts of Lisp modes.")
|
|
|
|
|
|
|
|
|
|
(defcustom lisp-mode-hook nil
|
|
|
|
|
"Hook run when entering Lisp mode."
|
|
|
|
|
:options '(imenu-add-menubar-index)
|
|
|
|
|
:type 'hook
|
|
|
|
|
:group 'lisp)
|
|
|
|
|
|
|
|
|
|
(defcustom lisp-interaction-mode-hook nil
|
|
|
|
|
"Hook run when entering Lisp Interaction mode."
|
2014-01-30 07:42:57 +00:00
|
|
|
|
:options '(eldoc-mode)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
:type 'hook
|
|
|
|
|
:group 'lisp)
|
|
|
|
|
|
2013-06-05 14:26:50 +00:00
|
|
|
|
(defconst lisp--prettify-symbols-alist
|
|
|
|
|
'(("lambda" . ?λ)))
|
|
|
|
|
|
2012-09-10 01:16:13 +00:00
|
|
|
|
;;; Generic Lisp mode.
|
|
|
|
|
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(defvar lisp-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap))
|
|
|
|
|
(menu-map (make-sparse-keymap "Lisp")))
|
|
|
|
|
(set-keymap-parent map lisp-mode-shared-map)
|
|
|
|
|
(define-key map "\e\C-x" 'lisp-eval-defun)
|
|
|
|
|
(define-key map "\C-c\C-z" 'run-lisp)
|
2012-06-27 21:15:13 +00:00
|
|
|
|
(bindings--define-key map [menu-bar lisp] (cons "Lisp" menu-map))
|
|
|
|
|
(bindings--define-key menu-map [run-lisp]
|
|
|
|
|
'(menu-item "Run inferior Lisp" run-lisp
|
|
|
|
|
:help "Run an inferior Lisp process, input and output via buffer `*inferior-lisp*'"))
|
|
|
|
|
(bindings--define-key menu-map [ev-def]
|
|
|
|
|
'(menu-item "Eval defun" lisp-eval-defun
|
|
|
|
|
:help "Send the current defun to the Lisp process made by M-x run-lisp"))
|
|
|
|
|
(bindings--define-key menu-map [ind-sexp]
|
|
|
|
|
'(menu-item "Indent sexp" indent-sexp
|
|
|
|
|
:help "Indent each line of the list starting just after point"))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
map)
|
|
|
|
|
"Keymap for ordinary Lisp mode.
|
|
|
|
|
All commands in `lisp-mode-shared-map' are inherited by this map.")
|
|
|
|
|
|
2010-05-14 16:41:01 +00:00
|
|
|
|
(define-derived-mode lisp-mode prog-mode "Lisp"
|
2008-09-23 17:59:28 +00:00
|
|
|
|
"Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.
|
|
|
|
|
Commands:
|
|
|
|
|
Delete converts tabs to spaces as it moves back.
|
|
|
|
|
Blank lines separate paragraphs. Semicolons start comments.
|
2009-01-04 19:32:40 +00:00
|
|
|
|
|
2008-09-23 17:59:28 +00:00
|
|
|
|
\\{lisp-mode-map}
|
|
|
|
|
Note that `run-lisp' may be used either to start an inferior Lisp job
|
2013-11-05 09:47:47 +00:00
|
|
|
|
or to switch back to an existing one."
|
2013-02-17 16:58:12 +00:00
|
|
|
|
(lisp-mode-variables nil t)
|
Convert several major modes to setq-local.
* emacs-lisp/lisp-mode.el (lisp-mode-variables, lisp-mode):
* progmodes/autoconf.el (autoconf-mode):
* progmodes/js.el (js-mode):
* progmodes/make-mode.el (makefile-mode, makefile-makepp-mode)
(makefile-bsdmake-mode, makefile-imake-mode, makefile-browse):
* progmodes/perl-mode.el (perl-mode):
* progmodes/sh-script.el (sh-mode, sh-set-shell):
* textmodes/css-mode.el (css-mode):
* textmodes/sgml-mode.el (html-mode, sgml-mode)
(sgml-tags-invisible, sgml-guess-indent):
* textmodes/tex-mode.el (tex-common-initialization)
(latex-complete-bibtex-keys, tex-shell, tex-main-file)
(doctex-mode, plain-tex-mode, latex-mode):
* textmodes/texinfo.el (texinfo-mode): Use setq-local.
2012-12-01 04:09:55 +00:00
|
|
|
|
(setq-local find-tag-default-function 'lisp-find-tag-default)
|
|
|
|
|
(setq-local comment-start-skip
|
|
|
|
|
"\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *")
|
2010-05-01 01:29:12 +00:00
|
|
|
|
(setq imenu-case-fold-search t))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
|
|
|
|
(defun lisp-find-tag-default ()
|
|
|
|
|
(let ((default (find-tag-default)))
|
|
|
|
|
(when (stringp default)
|
|
|
|
|
(if (string-match ":+" default)
|
|
|
|
|
(substring default (match-end 0))
|
|
|
|
|
default))))
|
|
|
|
|
|
|
|
|
|
;; Used in old LispM code.
|
|
|
|
|
(defalias 'common-lisp-mode 'lisp-mode)
|
|
|
|
|
|
|
|
|
|
;; This will do unless inf-lisp.el is loaded.
|
2013-08-08 23:59:14 +00:00
|
|
|
|
(defun lisp-eval-defun (&optional _and-go)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
"Send the current defun to the Lisp process made by \\[run-lisp]."
|
|
|
|
|
(interactive)
|
|
|
|
|
(error "Process lisp does not exist"))
|
|
|
|
|
|
|
|
|
|
;; May still be used by some external Lisp-mode variant.
|
|
|
|
|
(define-obsolete-function-alias 'lisp-comment-indent
|
|
|
|
|
'comment-indent-default "22.1")
|
|
|
|
|
(define-obsolete-function-alias 'lisp-mode-auto-fill 'do-auto-fill "23.1")
|
|
|
|
|
|
|
|
|
|
(defcustom lisp-indent-offset nil
|
|
|
|
|
"If non-nil, indent second line of expressions that many more columns."
|
|
|
|
|
:group 'lisp
|
|
|
|
|
:type '(choice (const nil) integer))
|
2009-06-22 06:24:32 +00:00
|
|
|
|
(put 'lisp-indent-offset 'safe-local-variable
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(lambda (x) (or (null x) (integerp x))))
|
|
|
|
|
|
2009-06-22 06:24:32 +00:00
|
|
|
|
(defcustom lisp-indent-function 'lisp-indent-function
|
2009-06-21 01:39:43 +00:00
|
|
|
|
"A function to be called by `calculate-lisp-indent'.
|
|
|
|
|
It indents the arguments of a Lisp function call. This function
|
|
|
|
|
should accept two arguments: the indent-point, and the
|
|
|
|
|
`parse-partial-sexp' state at that position. One option for this
|
2009-06-22 06:24:32 +00:00
|
|
|
|
function is `common-lisp-indent-function'."
|
|
|
|
|
:type 'function
|
|
|
|
|
:group 'lisp)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
2013-08-08 23:59:14 +00:00
|
|
|
|
(defun lisp-indent-line (&optional _whole-exp)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
"Indent current line as Lisp code.
|
|
|
|
|
With argument, indent any additional lines of the same expression
|
|
|
|
|
rigidly along with this one."
|
|
|
|
|
(interactive "P")
|
2013-08-08 23:59:14 +00:00
|
|
|
|
(let ((indent (calculate-lisp-indent)) shift-amt
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(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
|
|
|
|
|
;; or a line that starts in a string.
|
2012-09-10 01:16:13 +00:00
|
|
|
|
;; FIXME: inconsistency: comment-indent moves ;;; to column 0.
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(goto-char (- (point-max) pos))
|
|
|
|
|
(if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
|
|
|
|
|
;; Single-semicolon comment lines should be indented
|
|
|
|
|
;; as comment lines, not as code.
|
|
|
|
|
(progn (indent-for-comment) (forward-char -1))
|
|
|
|
|
(if (listp indent) (setq indent (car indent)))
|
|
|
|
|
(setq shift-amt (- indent (current-column)))
|
|
|
|
|
(if (zerop shift-amt)
|
|
|
|
|
nil
|
|
|
|
|
(delete-region beg (point))
|
|
|
|
|
(indent-to indent)))
|
|
|
|
|
;; If initial point was within line's indentation,
|
|
|
|
|
;; position after the indentation. Else stay at same point in text.
|
|
|
|
|
(if (> (- (point-max) pos) (point))
|
2012-09-10 01:16:13 +00:00
|
|
|
|
(goto-char (- (point-max) pos))))))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
|
|
|
|
(defvar calculate-lisp-indent-last-sexp)
|
|
|
|
|
|
|
|
|
|
(defun calculate-lisp-indent (&optional parse-start)
|
|
|
|
|
"Return appropriate indentation for current line as Lisp code.
|
|
|
|
|
In usual case returns an integer: the column to indent to.
|
|
|
|
|
If the value is nil, that means don't change the indentation
|
|
|
|
|
because the line starts inside a string.
|
|
|
|
|
|
|
|
|
|
The value can also be a list of the form (COLUMN CONTAINING-SEXP-START).
|
|
|
|
|
This means that following lines at the same level of indentation
|
|
|
|
|
should not necessarily be indented the same as this line.
|
|
|
|
|
Then COLUMN is the column to indent to, and CONTAINING-SEXP-START
|
|
|
|
|
is the buffer position of the start of the containing expression."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(let ((indent-point (point))
|
2013-08-08 23:59:14 +00:00
|
|
|
|
state
|
2008-09-23 17:59:28 +00:00
|
|
|
|
;; setting this to a number inhibits calling hook
|
|
|
|
|
(desired-indent nil)
|
|
|
|
|
(retry t)
|
|
|
|
|
calculate-lisp-indent-last-sexp containing-sexp)
|
|
|
|
|
(if parse-start
|
|
|
|
|
(goto-char parse-start)
|
|
|
|
|
(beginning-of-defun))
|
|
|
|
|
;; Find outermost containing sexp
|
|
|
|
|
(while (< (point) indent-point)
|
|
|
|
|
(setq state (parse-partial-sexp (point) indent-point 0)))
|
|
|
|
|
;; Find innermost containing sexp
|
|
|
|
|
(while (and retry
|
|
|
|
|
state
|
2013-08-08 23:59:14 +00:00
|
|
|
|
(> (elt state 0) 0))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(setq retry nil)
|
|
|
|
|
(setq calculate-lisp-indent-last-sexp (elt state 2))
|
|
|
|
|
(setq containing-sexp (elt state 1))
|
|
|
|
|
;; Position following last unclosed open.
|
|
|
|
|
(goto-char (1+ containing-sexp))
|
|
|
|
|
;; Is there a complete sexp since then?
|
|
|
|
|
(if (and calculate-lisp-indent-last-sexp
|
|
|
|
|
(> calculate-lisp-indent-last-sexp (point)))
|
|
|
|
|
;; Yes, but is there a containing sexp after that?
|
|
|
|
|
(let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp
|
|
|
|
|
indent-point 0)))
|
|
|
|
|
(if (setq retry (car (cdr peek))) (setq state peek)))))
|
|
|
|
|
(if retry
|
|
|
|
|
nil
|
|
|
|
|
;; Innermost containing sexp found
|
|
|
|
|
(goto-char (1+ containing-sexp))
|
|
|
|
|
(if (not calculate-lisp-indent-last-sexp)
|
|
|
|
|
;; indent-point immediately follows open paren.
|
|
|
|
|
;; Don't call hook.
|
|
|
|
|
(setq desired-indent (current-column))
|
|
|
|
|
;; Find the start of first element of containing sexp.
|
|
|
|
|
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
|
|
|
|
|
(cond ((looking-at "\\s(")
|
|
|
|
|
;; First element of containing sexp is a list.
|
|
|
|
|
;; Indent under that list.
|
|
|
|
|
)
|
|
|
|
|
((> (save-excursion (forward-line 1) (point))
|
|
|
|
|
calculate-lisp-indent-last-sexp)
|
|
|
|
|
;; This is the first line to start within the containing sexp.
|
|
|
|
|
;; It's almost certainly a function call.
|
|
|
|
|
(if (= (point) calculate-lisp-indent-last-sexp)
|
|
|
|
|
;; Containing sexp has nothing before this line
|
|
|
|
|
;; except the first element. Indent under that element.
|
|
|
|
|
nil
|
|
|
|
|
;; Skip the first element, find start of second (the first
|
|
|
|
|
;; argument of the function call) and indent under.
|
|
|
|
|
(progn (forward-sexp 1)
|
|
|
|
|
(parse-partial-sexp (point)
|
|
|
|
|
calculate-lisp-indent-last-sexp
|
|
|
|
|
0 t)))
|
|
|
|
|
(backward-prefix-chars))
|
|
|
|
|
(t
|
|
|
|
|
;; Indent beneath first sexp on same line as
|
|
|
|
|
;; `calculate-lisp-indent-last-sexp'. Again, it's
|
|
|
|
|
;; almost certainly a function call.
|
|
|
|
|
(goto-char calculate-lisp-indent-last-sexp)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp
|
|
|
|
|
0 t)
|
|
|
|
|
(backward-prefix-chars)))))
|
|
|
|
|
;; Point is at the point to indent under unless we are inside a string.
|
|
|
|
|
;; Call indentation hook except when overridden by lisp-indent-offset
|
|
|
|
|
;; or if the desired indentation has already been computed.
|
|
|
|
|
(let ((normal-indent (current-column)))
|
|
|
|
|
(cond ((elt state 3)
|
|
|
|
|
;; Inside a string, don't change indentation.
|
|
|
|
|
nil)
|
|
|
|
|
((and (integerp lisp-indent-offset) containing-sexp)
|
|
|
|
|
;; Indent by constant offset
|
|
|
|
|
(goto-char containing-sexp)
|
|
|
|
|
(+ (current-column) lisp-indent-offset))
|
|
|
|
|
;; in this case calculate-lisp-indent-last-sexp is not nil
|
|
|
|
|
(calculate-lisp-indent-last-sexp
|
|
|
|
|
(or
|
|
|
|
|
;; try to align the parameters of a known function
|
|
|
|
|
(and lisp-indent-function
|
|
|
|
|
(not retry)
|
|
|
|
|
(funcall lisp-indent-function indent-point state))
|
|
|
|
|
;; If the function has no special alignment
|
|
|
|
|
;; or it does not apply to this argument,
|
|
|
|
|
;; try to align a constant-symbol under the last
|
|
|
|
|
;; preceding constant symbol, if there is such one of
|
|
|
|
|
;; the last 2 preceding symbols, in the previous
|
|
|
|
|
;; uncommented line.
|
|
|
|
|
(and (save-excursion
|
|
|
|
|
(goto-char indent-point)
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
(looking-at ":"))
|
|
|
|
|
;; The last sexp may not be at the indentation
|
|
|
|
|
;; where it begins, so find that one, instead.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char calculate-lisp-indent-last-sexp)
|
|
|
|
|
;; Handle prefix characters and whitespace
|
|
|
|
|
;; following an open paren. (Bug#1012)
|
|
|
|
|
(backward-prefix-chars)
|
2015-04-21 01:55:00 +00:00
|
|
|
|
(while (not (or (looking-back "^[ \t]*\\|([ \t]+"
|
|
|
|
|
(line-beginning-position))
|
|
|
|
|
(and containing-sexp
|
|
|
|
|
(>= (1+ containing-sexp) (point)))))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(forward-sexp -1)
|
|
|
|
|
(backward-prefix-chars))
|
|
|
|
|
(setq calculate-lisp-indent-last-sexp (point)))
|
|
|
|
|
(> calculate-lisp-indent-last-sexp
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (1+ containing-sexp))
|
|
|
|
|
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
|
|
|
|
|
(point)))
|
|
|
|
|
(let ((parse-sexp-ignore-comments t)
|
|
|
|
|
indent)
|
|
|
|
|
(goto-char calculate-lisp-indent-last-sexp)
|
|
|
|
|
(or (and (looking-at ":")
|
|
|
|
|
(setq indent (current-column)))
|
Use line-end-position rather than end-of-line, etc.
* textmodes/texnfo-upd.el (texinfo-start-menu-description)
(texinfo-update-menu-region-beginning, texinfo-menu-first-node)
(texinfo-delete-existing-pointers, texinfo-find-pointer)
(texinfo-clean-up-node-line, texinfo-insert-node-lines)
(texinfo-multiple-files-update):
* textmodes/table.el (table--probe-cell-left-up)
(table--probe-cell-right-bottom):
* textmodes/picture.el (picture-tab-search):
* textmodes/page-ext.el (pages-copy-header-and-position)
(pages-directory-for-addresses):
* progmodes/vera-mode.el (vera-get-offset):
* progmodes/simula.el (simula-calculate-indent):
* progmodes/python.el (python-pdbtrack-overlay-arrow):
* progmodes/prolog.el (end-of-prolog-clause):
* progmodes/perl-mode.el (perl-calculate-indent, perl-indent-exp):
* progmodes/icon.el (indent-icon-exp):
* progmodes/etags.el (tag-re-match-p):
* progmodes/ebrowse.el (ebrowse-show-file-name-at-point):
* progmodes/ebnf2ps.el (ebnf-begin-file):
* progmodes/dcl-mode.el (dcl-back-to-indentation-1)
(dcl-save-local-variable):
* play/life.el (life-setup):
* play/gametree.el (gametree-looking-at-ply):
* nxml/nxml-maint.el (nxml-insert-target-repertoire-glyph-set):
* mail/sendmail.el (mail-mode-auto-fill):
* emacs-lisp/lisp-mode.el (calculate-lisp-indent):
* emacs-lisp/edebug.el (edebug-overlay-arrow):
* emacs-lisp/checkdoc.el (checkdoc-this-string-valid):
* woman.el (woman-parse-numeric-value, woman2-TH, woman2-SH)
(woman-tab-to-tab-stop, WoMan-warn-ignored):
* type-break.el (type-break-file-keystroke-count):
* term.el (term-replace-by-expanded-history-before-point)
(term-skip-prompt, term-extract-string):
* speedbar.el (speedbar-edit-line, speedbar-expand-line)
(speedbar-contract-line, speedbar-toggle-line-expansion)
(speedbar-parse-c-or-c++tag, speedbar-parse-tex-string)
(speedbar-buffer-revert-buffer, speedbar-highlight-one-tag-line):
* sort.el (sort-skip-fields):
* skeleton.el (skeleton-internal-list):
* simple.el (line-move-finish, line-move-to-column):
* shell.el (shell-forward-command):
* misc.el (copy-from-above-command):
* makesum.el (double-column):
* ebuff-menu.el (electric-buffer-update-highlight):
* dired.el (dired-move-to-end-of-filename):
* dframe.el (dframe-popup-kludge):
* bookmark.el (bookmark-kill-line, bookmark-bmenu-show-filenames):
* arc-mode.el (archive-get-lineno):
Use line-end-position and line-beginning-position.
* net/ange-ftp.el, progmodes/hideif.el, reposition.el:
Same, but only in comments.
2010-11-06 20:23:42 +00:00
|
|
|
|
(and (< (line-beginning-position)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(prog2 (backward-sexp) (point)))
|
|
|
|
|
(looking-at ":")
|
|
|
|
|
(setq indent (current-column))))
|
|
|
|
|
indent))
|
|
|
|
|
;; another symbols or constants not preceded by a constant
|
|
|
|
|
;; as defined above.
|
|
|
|
|
normal-indent))
|
|
|
|
|
;; in this case calculate-lisp-indent-last-sexp is nil
|
|
|
|
|
(desired-indent)
|
|
|
|
|
(t
|
|
|
|
|
normal-indent))))))
|
|
|
|
|
|
|
|
|
|
(defun lisp-indent-function (indent-point state)
|
|
|
|
|
"This function is the normal value of the variable `lisp-indent-function'.
|
2011-09-13 06:55:10 +00:00
|
|
|
|
The function `calculate-lisp-indent' calls this to determine
|
|
|
|
|
if the arguments of a Lisp function call should be indented specially.
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
2013-01-16 02:03:06 +00:00
|
|
|
|
INDENT-POINT is the position at which the line being indented begins.
|
2008-09-23 17:59:28 +00:00
|
|
|
|
Point is located at the point to indent under (for default indentation);
|
|
|
|
|
STATE is the `parse-partial-sexp' state for that position.
|
|
|
|
|
|
2011-09-13 06:55:10 +00:00
|
|
|
|
If the current line is in a call to a Lisp function that has a non-nil
|
|
|
|
|
property `lisp-indent-function' (or the deprecated `lisp-indent-hook'),
|
|
|
|
|
it specifies how to indent. The property value can be:
|
|
|
|
|
|
|
|
|
|
* `defun', meaning indent `defun'-style
|
2015-09-17 23:08:20 +00:00
|
|
|
|
(this is also the case if there is no property and the function
|
2011-09-13 06:55:10 +00:00
|
|
|
|
has a name that begins with \"def\", and three or more arguments);
|
|
|
|
|
|
2008-09-23 17:59:28 +00:00
|
|
|
|
* an integer N, meaning indent the first N arguments specially
|
2011-09-13 06:55:10 +00:00
|
|
|
|
(like ordinary function arguments), and then indent any further
|
2008-09-23 17:59:28 +00:00
|
|
|
|
arguments like a body;
|
|
|
|
|
|
2011-09-13 06:55:10 +00:00
|
|
|
|
* a function to call that returns the indentation (or nil).
|
|
|
|
|
`lisp-indent-function' calls this function with the same two arguments
|
|
|
|
|
that it itself received.
|
|
|
|
|
|
|
|
|
|
This function returns either the indentation to use, or nil if the
|
|
|
|
|
Lisp function does not specify a special indentation."
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(let ((normal-indent (current-column)))
|
|
|
|
|
(goto-char (1+ (elt state 1)))
|
|
|
|
|
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
|
|
|
|
|
(if (and (elt state 2)
|
|
|
|
|
(not (looking-at "\\sw\\|\\s_")))
|
|
|
|
|
;; car of form doesn't seem to be a symbol
|
|
|
|
|
(progn
|
|
|
|
|
(if (not (> (save-excursion (forward-line 1) (point))
|
|
|
|
|
calculate-lisp-indent-last-sexp))
|
|
|
|
|
(progn (goto-char calculate-lisp-indent-last-sexp)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(parse-partial-sexp (point)
|
|
|
|
|
calculate-lisp-indent-last-sexp 0 t)))
|
|
|
|
|
;; Indent under the list or under the first sexp on the same
|
|
|
|
|
;; line as calculate-lisp-indent-last-sexp. Note that first
|
|
|
|
|
;; thing on that line has to be complete sexp since we are
|
|
|
|
|
;; inside the innermost containing sexp.
|
|
|
|
|
(backward-prefix-chars)
|
|
|
|
|
(current-column))
|
|
|
|
|
(let ((function (buffer-substring (point)
|
|
|
|
|
(progn (forward-sexp 1) (point))))
|
|
|
|
|
method)
|
2012-07-26 01:27:33 +00:00
|
|
|
|
(setq method (or (function-get (intern-soft function)
|
|
|
|
|
'lisp-indent-function)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(get (intern-soft function) 'lisp-indent-hook)))
|
|
|
|
|
(cond ((or (eq method 'defun)
|
|
|
|
|
(and (null method)
|
|
|
|
|
(> (length function) 3)
|
|
|
|
|
(string-match "\\`def" function)))
|
|
|
|
|
(lisp-indent-defform state indent-point))
|
|
|
|
|
((integerp method)
|
|
|
|
|
(lisp-indent-specform method state
|
|
|
|
|
indent-point normal-indent))
|
|
|
|
|
(method
|
|
|
|
|
(funcall method indent-point state)))))))
|
|
|
|
|
|
|
|
|
|
(defcustom lisp-body-indent 2
|
|
|
|
|
"Number of columns to indent the second line of a `(def...)' form."
|
|
|
|
|
:group 'lisp
|
|
|
|
|
:type 'integer)
|
|
|
|
|
(put 'lisp-body-indent 'safe-local-variable 'integerp)
|
|
|
|
|
|
|
|
|
|
(defun lisp-indent-specform (count state indent-point normal-indent)
|
|
|
|
|
(let ((containing-form-start (elt state 1))
|
|
|
|
|
(i count)
|
|
|
|
|
body-indent containing-form-column)
|
|
|
|
|
;; Move to the start of containing form, calculate indentation
|
|
|
|
|
;; to use for non-distinguished forms (> count), and move past the
|
|
|
|
|
;; function symbol. lisp-indent-function guarantees that there is at
|
|
|
|
|
;; least one word or symbol character following open paren of containing
|
|
|
|
|
;; form.
|
|
|
|
|
(goto-char containing-form-start)
|
|
|
|
|
(setq containing-form-column (current-column))
|
|
|
|
|
(setq body-indent (+ lisp-body-indent containing-form-column))
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(forward-sexp 1)
|
|
|
|
|
;; Now find the start of the last form.
|
|
|
|
|
(parse-partial-sexp (point) indent-point 1 t)
|
|
|
|
|
(while (and (< (point) indent-point)
|
|
|
|
|
(condition-case ()
|
|
|
|
|
(progn
|
|
|
|
|
(setq count (1- count))
|
|
|
|
|
(forward-sexp 1)
|
|
|
|
|
(parse-partial-sexp (point) indent-point 1 t))
|
|
|
|
|
(error nil))))
|
|
|
|
|
;; Point is sitting on first character of last (or count) sexp.
|
|
|
|
|
(if (> count 0)
|
|
|
|
|
;; A distinguished form. If it is the first or second form use double
|
|
|
|
|
;; lisp-body-indent, else normal indent. With lisp-body-indent bound
|
|
|
|
|
;; to 2 (the default), this just happens to work the same with if as
|
|
|
|
|
;; the older code, but it makes unwind-protect, condition-case,
|
|
|
|
|
;; with-output-to-temp-buffer, et. al. much more tasteful. The older,
|
|
|
|
|
;; less hacked, behavior can be obtained by replacing below with
|
|
|
|
|
;; (list normal-indent containing-form-start).
|
|
|
|
|
(if (<= (- i count) 1)
|
|
|
|
|
(list (+ containing-form-column (* 2 lisp-body-indent))
|
|
|
|
|
containing-form-start)
|
|
|
|
|
(list normal-indent containing-form-start))
|
|
|
|
|
;; A non-distinguished form. Use body-indent if there are no
|
|
|
|
|
;; distinguished forms and this is the first undistinguished form,
|
|
|
|
|
;; or if this is the first undistinguished form and the preceding
|
|
|
|
|
;; distinguished form has indentation at least as great as body-indent.
|
|
|
|
|
(if (or (and (= i 0) (= count 0))
|
|
|
|
|
(and (= count 0) (<= body-indent normal-indent)))
|
|
|
|
|
body-indent
|
|
|
|
|
normal-indent))))
|
|
|
|
|
|
2013-08-08 23:59:14 +00:00
|
|
|
|
(defun lisp-indent-defform (state _indent-point)
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(goto-char (car (cdr state)))
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(if (> (point) (car (cdr (cdr state))))
|
|
|
|
|
(progn
|
|
|
|
|
(goto-char (car (cdr state)))
|
|
|
|
|
(+ lisp-body-indent (current-column)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented
|
|
|
|
|
;; like defun if the first form is placed on the next line, otherwise
|
|
|
|
|
;; it is indented like any other form (i.e. forms line up under first).
|
|
|
|
|
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
(put 'autoload 'lisp-indent-function 'defun) ;Elisp
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(put 'progn 'lisp-indent-function 0)
|
|
|
|
|
(put 'prog1 'lisp-indent-function 1)
|
|
|
|
|
(put 'prog2 'lisp-indent-function 2)
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
(put 'save-excursion 'lisp-indent-function 0) ;Elisp
|
|
|
|
|
(put 'save-restriction 'lisp-indent-function 0) ;Elisp
|
|
|
|
|
(put 'save-current-buffer 'lisp-indent-function 0) ;Elisp
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(put 'let 'lisp-indent-function 1)
|
|
|
|
|
(put 'let* 'lisp-indent-function 1)
|
|
|
|
|
(put 'while 'lisp-indent-function 1)
|
|
|
|
|
(put 'if 'lisp-indent-function 2)
|
|
|
|
|
(put 'catch 'lisp-indent-function 1)
|
|
|
|
|
(put 'condition-case 'lisp-indent-function 2)
|
Introduce global-eldoc-mode. Move Elisp-specific code to elisp-mode.el.
* lisp/emacs-lisp/eldoc.el (global-eldoc-mode): New minor mode.
(eldoc-schedule-timer): Obey it.
(eldoc-documentation-function): Default to nil.
(eldoc-mode): Don't enable if eldoc-documentation-function is not set.
(eldoc-documentation-function-default, eldoc-get-fnsym-args-string)
(eldoc-highlight-function-argument, eldoc-get-var-docstring)
(eldoc-last-data-store, eldoc-docstring-first-line)
(eldoc-docstring-format-sym-doc, eldoc-fnsym-in-current-sexp)
(eldoc-beginning-of-sexp, eldoc-current-symbol)
(eldoc-function-argstring): Move to elisp-mode.el.
(eldoc-symbol-function): Remove, unused.
* lisp/progmodes/elisp-mode.el: New file. Rename all "eldoc-*" to "elisp--*".
(elisp-completion-at-point): Rename from lisp-completion-at-point.
(elisp--preceding-sexp): Rename from preceding-sexp.
* lisp/loadup.el: Load new file progmodes/elisp-mode.
* lisp/ielm.el (inferior-emacs-lisp-mode): Set eldoc-documentation-function.
* lisp/emacs-lisp/lisp.el (lisp--local-variables-1, lisp--local-variables)
(lisp--local-variables-completion-table, lisp--expect-function-p)
(lisp--form-quoted-p, lisp--company-doc-buffer)
(lisp--company-doc-string, lisp--company-location)
(lisp-completion-at-point): Move to elisp-mode.el.
* lisp/emacs-lisp/lisp-mode.el (lisp--mode-syntax-table): New syntax-table,
extracted from emacs-lisp-mode-syntax-table.
(emacs-lisp-mode-abbrev-table, emacs-lisp-mode-syntax-table): Move to
elisp-mode.el.
(lisp-imenu-generic-expression): Add comments to document what comes
from which Lisp dialect.
(emacs-lisp-mode-map, emacs-lisp-byte-compile)
(emacs-lisp-byte-compile-and-load, emacs-lisp-mode-hook)
(emacs-lisp-mode, emacs-list-byte-code-comment-re)
(emacs-lisp-byte-code-comment)
(emacs-lisp-byte-code-syntax-propertize, emacs-lisp-byte-code-mode)
(lisp-interaction-mode-map, lisp-interaction-mode)
(eval-print-last-sexp, last-sexp-setup-props)
(last-sexp-toggle-display, prin1-char, preceding-sexp)
(eval-last-sexp-1, eval-last-sexp-print-value)
(eval-last-sexp-fake-value, eval-sexp-add-defvars, eval-last-sexp)
(eval-defun-1, eval-defun-2, eval-defun): Move to elisp-mode.el.
* src/lisp.mk (lisp): Add elisp-mode.elc.
2014-09-27 03:57:41 +00:00
|
|
|
|
(put 'handler-case 'lisp-indent-function 1) ;CL
|
|
|
|
|
(put 'handler-bind 'lisp-indent-function 1) ;CL
|
2008-09-23 17:59:28 +00:00
|
|
|
|
(put 'unwind-protect 'lisp-indent-function 1)
|
|
|
|
|
(put 'with-output-to-temp-buffer 'lisp-indent-function 1)
|
|
|
|
|
|
|
|
|
|
(defun indent-sexp (&optional endpos)
|
|
|
|
|
"Indent each line of the list starting just after point.
|
|
|
|
|
If optional arg ENDPOS is given, indent each line, stopping when
|
|
|
|
|
ENDPOS is encountered."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((indent-stack (list nil))
|
|
|
|
|
(next-depth 0)
|
|
|
|
|
;; If ENDPOS is non-nil, use nil as STARTING-POINT
|
|
|
|
|
;; so that calculate-lisp-indent will find the beginning of
|
|
|
|
|
;; the defun we are in.
|
|
|
|
|
;; If ENDPOS is nil, it is safe not to scan before point
|
|
|
|
|
;; since every line we indent is more deeply nested than point is.
|
|
|
|
|
(starting-point (if endpos nil (point)))
|
|
|
|
|
(last-point (point))
|
|
|
|
|
last-depth bol outer-loop-done inner-loop-done state this-indent)
|
|
|
|
|
(or endpos
|
|
|
|
|
;; Get error now if we don't have a complete sexp after point.
|
|
|
|
|
(save-excursion (forward-sexp 1)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(setq outer-loop-done nil)
|
|
|
|
|
(while (if endpos (< (point) endpos)
|
|
|
|
|
(not outer-loop-done))
|
|
|
|
|
(setq last-depth next-depth
|
|
|
|
|
inner-loop-done nil)
|
|
|
|
|
;; Parse this line so we can learn the state
|
|
|
|
|
;; to indent the next line.
|
|
|
|
|
;; This inner loop goes through only once
|
|
|
|
|
;; unless a line ends inside a string.
|
|
|
|
|
(while (and (not inner-loop-done)
|
|
|
|
|
(not (setq outer-loop-done (eobp))))
|
|
|
|
|
(setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
|
|
|
|
|
nil nil state))
|
|
|
|
|
(setq next-depth (car state))
|
|
|
|
|
;; If the line contains a comment other than the sort
|
|
|
|
|
;; that is indented like code,
|
|
|
|
|
;; indent it now with indent-for-comment.
|
|
|
|
|
;; Comments indented like code are right already.
|
|
|
|
|
;; In any case clear the in-comment flag in the state
|
|
|
|
|
;; because parse-partial-sexp never sees the newlines.
|
|
|
|
|
(if (car (nthcdr 4 state))
|
|
|
|
|
(progn (indent-for-comment)
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(setcar (nthcdr 4 state) nil)))
|
|
|
|
|
;; If this line ends inside a string,
|
|
|
|
|
;; go straight to next line, remaining within the inner loop,
|
|
|
|
|
;; and turn off the \-flag.
|
|
|
|
|
(if (car (nthcdr 3 state))
|
|
|
|
|
(progn
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(setcar (nthcdr 5 state) nil))
|
|
|
|
|
(setq inner-loop-done t)))
|
|
|
|
|
(and endpos
|
|
|
|
|
(<= next-depth 0)
|
|
|
|
|
(progn
|
|
|
|
|
(setq indent-stack (nconc indent-stack
|
|
|
|
|
(make-list (- next-depth) nil))
|
|
|
|
|
last-depth (- last-depth next-depth)
|
|
|
|
|
next-depth 0)))
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
;; Decide whether to exit.
|
|
|
|
|
(if endpos
|
|
|
|
|
;; If we have already reached the specified end,
|
|
|
|
|
;; give up and do not reindent this line.
|
|
|
|
|
(if (<= endpos (point))
|
|
|
|
|
(setq outer-loop-done t))
|
|
|
|
|
;; If no specified end, we are done if we have finished one sexp.
|
|
|
|
|
(if (<= next-depth 0)
|
|
|
|
|
(setq outer-loop-done t)))
|
|
|
|
|
(unless outer-loop-done
|
|
|
|
|
(while (> last-depth next-depth)
|
|
|
|
|
(setq indent-stack (cdr indent-stack)
|
|
|
|
|
last-depth (1- last-depth)))
|
|
|
|
|
(while (< last-depth next-depth)
|
|
|
|
|
(setq indent-stack (cons nil indent-stack)
|
|
|
|
|
last-depth (1+ last-depth)))
|
|
|
|
|
;; Now indent the next line according
|
|
|
|
|
;; to what we learned from parsing the previous one.
|
|
|
|
|
(setq bol (point))
|
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
|
;; But not if the line is blank, or just a comment
|
|
|
|
|
;; (except for double-semi comments; indent them as usual).
|
|
|
|
|
(if (or (eobp) (looking-at "\\s<\\|\n"))
|
|
|
|
|
nil
|
|
|
|
|
(if (and (car indent-stack)
|
|
|
|
|
(>= (car indent-stack) 0))
|
|
|
|
|
(setq this-indent (car indent-stack))
|
|
|
|
|
(let ((val (calculate-lisp-indent
|
|
|
|
|
(if (car indent-stack) (- (car indent-stack))
|
|
|
|
|
starting-point))))
|
|
|
|
|
(if (null val)
|
|
|
|
|
(setq this-indent val)
|
|
|
|
|
(if (integerp val)
|
|
|
|
|
(setcar indent-stack
|
|
|
|
|
(setq this-indent val))
|
|
|
|
|
(setcar indent-stack (- (car (cdr val))))
|
|
|
|
|
(setq this-indent (car val))))))
|
|
|
|
|
(if (and this-indent (/= (current-column) this-indent))
|
|
|
|
|
(progn (delete-region bol (point))
|
|
|
|
|
(indent-to this-indent)))))
|
|
|
|
|
(or outer-loop-done
|
|
|
|
|
(setq outer-loop-done (= (point) last-point))
|
|
|
|
|
(setq last-point (point)))))))
|
|
|
|
|
|
|
|
|
|
(defun indent-pp-sexp (&optional arg)
|
|
|
|
|
"Indent each line of the list starting just after point, or prettyprint it.
|
|
|
|
|
A prefix argument specifies pretty-printing."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(if arg
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region (point) (progn (forward-sexp 1) (point)))
|
|
|
|
|
(pp-buffer)
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(if (eq (char-before) ?\n)
|
|
|
|
|
(delete-char -1)))))
|
|
|
|
|
(indent-sexp))
|
|
|
|
|
|
|
|
|
|
;;;; Lisp paragraph filling commands.
|
|
|
|
|
|
|
|
|
|
(defcustom emacs-lisp-docstring-fill-column 65
|
|
|
|
|
"Value of `fill-column' to use when filling a docstring.
|
|
|
|
|
Any non-integer value means do not use a different value of
|
|
|
|
|
`fill-column' when filling docstrings."
|
|
|
|
|
:type '(choice (integer)
|
|
|
|
|
(const :tag "Use the current `fill-column'" t))
|
|
|
|
|
:group 'lisp)
|
2013-03-23 22:04:40 +00:00
|
|
|
|
(put 'emacs-lisp-docstring-fill-column 'safe-local-variable
|
|
|
|
|
(lambda (x) (or (eq x t) (integerp x))))
|
2008-09-23 17:59:28 +00:00
|
|
|
|
|
|
|
|
|
(defun lisp-fill-paragraph (&optional justify)
|
|
|
|
|
"Like \\[fill-paragraph], but handle Emacs Lisp comments and docstrings.
|
|
|
|
|
If any of the current line is a comment, fill the comment or the
|
|
|
|
|
paragraph of it that point is in, preserving the comment's indentation
|
|
|
|
|
and initial semicolons."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(or (fill-comment-paragraph justify)
|
|
|
|
|
;; Since fill-comment-paragraph returned nil, that means we're not in
|
|
|
|
|
;; a comment: Point is on a program line; we are interested
|
|
|
|
|
;; particularly in docstring lines.
|
|
|
|
|
;;
|
|
|
|
|
;; We bind `paragraph-start' and `paragraph-separate' temporarily. They
|
|
|
|
|
;; are buffer-local, but we avoid changing them so that they can be set
|
|
|
|
|
;; to make `forward-paragraph' and friends do something the user wants.
|
|
|
|
|
;;
|
|
|
|
|
;; `paragraph-start': The `(' in the character alternative and the
|
|
|
|
|
;; left-singlequote plus `(' sequence after the \\| alternative prevent
|
|
|
|
|
;; sexps and backquoted sexps that follow a docstring from being filled
|
|
|
|
|
;; with the docstring. This setting has the consequence of inhibiting
|
|
|
|
|
;; filling many program lines that are not docstrings, which is sensible,
|
|
|
|
|
;; because the user probably asked to fill program lines by accident, or
|
|
|
|
|
;; expecting indentation (perhaps we should try to do indenting in that
|
|
|
|
|
;; case). The `;' and `:' stop the paragraph being filled at following
|
|
|
|
|
;; comment lines and at keywords (e.g., in `defcustom'). Left parens are
|
|
|
|
|
;; escaped to keep font-locking, filling, & paren matching in the source
|
|
|
|
|
;; file happy.
|
|
|
|
|
;;
|
|
|
|
|
;; `paragraph-separate': A clever regexp distinguishes the first line of
|
|
|
|
|
;; a docstring and identifies it as a paragraph separator, so that it
|
|
|
|
|
;; won't be filled. (Since the first line of documentation stands alone
|
|
|
|
|
;; in some contexts, filling should not alter the contents the author has
|
|
|
|
|
;; chosen.) Only the first line of a docstring begins with whitespace
|
|
|
|
|
;; and a quotation mark and ends with a period or (rarely) a comma.
|
|
|
|
|
;;
|
|
|
|
|
;; The `fill-column' is temporarily bound to
|
|
|
|
|
;; `emacs-lisp-docstring-fill-column' if that value is an integer.
|
|
|
|
|
(let ((paragraph-start (concat paragraph-start
|
|
|
|
|
"\\|\\s-*\\([(;:\"]\\|`(\\|#'(\\)"))
|
|
|
|
|
(paragraph-separate
|
|
|
|
|
(concat paragraph-separate "\\|\\s-*\".*[,\\.]$"))
|
|
|
|
|
(fill-column (if (and (integerp emacs-lisp-docstring-fill-column)
|
|
|
|
|
(derived-mode-p 'emacs-lisp-mode))
|
|
|
|
|
emacs-lisp-docstring-fill-column
|
|
|
|
|
fill-column)))
|
|
|
|
|
(fill-paragraph justify))
|
|
|
|
|
;; Never return nil.
|
|
|
|
|
t))
|
|
|
|
|
|
|
|
|
|
(defun indent-code-rigidly (start end arg &optional nochange-regexp)
|
|
|
|
|
"Indent all lines of code, starting in the region, sideways by ARG columns.
|
|
|
|
|
Does not affect lines starting inside comments or strings, assuming that
|
|
|
|
|
the start of the region is not inside them.
|
|
|
|
|
|
|
|
|
|
Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP.
|
|
|
|
|
The last is a regexp which, if matched at the beginning of a line,
|
|
|
|
|
means don't indent that line."
|
|
|
|
|
(interactive "r\np")
|
|
|
|
|
(let (state)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char end)
|
|
|
|
|
(setq end (point-marker))
|
|
|
|
|
(goto-char start)
|
|
|
|
|
(or (bolp)
|
|
|
|
|
(setq state (parse-partial-sexp (point)
|
|
|
|
|
(progn
|
|
|
|
|
(forward-line 1) (point))
|
|
|
|
|
nil nil state)))
|
|
|
|
|
(while (< (point) end)
|
|
|
|
|
(or (car (nthcdr 3 state))
|
|
|
|
|
(and nochange-regexp
|
|
|
|
|
(looking-at nochange-regexp))
|
|
|
|
|
;; If line does not start in string, indent it
|
|
|
|
|
(let ((indent (current-indentation)))
|
|
|
|
|
(delete-region (point) (progn (skip-chars-forward " \t") (point)))
|
|
|
|
|
(or (eolp)
|
|
|
|
|
(indent-to (max 0 (+ indent arg)) 0))))
|
|
|
|
|
(setq state (parse-partial-sexp (point)
|
|
|
|
|
(progn
|
|
|
|
|
(forward-line 1) (point))
|
|
|
|
|
nil nil state))))))
|
|
|
|
|
|
|
|
|
|
(provide 'lisp-mode)
|
|
|
|
|
|
|
|
|
|
;;; lisp-mode.el ends here
|