emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/add-lisp-data-mode b4af4a3: Add a lisp-data-mode for editing non


From: João Távora
Subject: scratch/add-lisp-data-mode b4af4a3: Add a lisp-data-mode for editing non-code lisp data
Date: Fri, 17 Apr 2020 22:02:01 -0400 (EDT)

branch: scratch/add-lisp-data-mode
commit b4af4a3578303741364dc91acdd5908d9b11e3a4
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Add a lisp-data-mode for editing non-code lisp data
    
    To provide a cleaner implementation remove arguments from the
    auxiliary routine lisp-mode-variables.  The modes/functions that need
    to do some something special adjustment do them in their own bodies.
    
    * lisp/chistory.el (command-history-mode): Don't pass nil to
    lisp-mode-variables.
    
    * lisp/files.el (auto-mode-alist): Add entry for ".dir-locals".
    
    * lisp/help-fns.el (describe-variable): Don't pass useless args to
    lisp-mode-variables.
    
    * lisp/emacs-lisp/pp.el (pp-to-string): Don't pass useless args to
    lisp-mode-variables.
    
    * lisp/emacs-lisp/lisp-mode.el (lisp-mode-variables):
    Simplify.  Always set same variables.
    (lisp-data-mode): New major mode.
    (lisp-mode): Inherit from lisp-data-mode.  Set special lisp-mode
    stuff here.
    
    * lisp/progmodes/elisp-mode.el (emacs-lisp-mode): Inherit from
    lisp-data-mode.
    (emacs-lisp-mode): Simplify.
    
    * lisp/progmodes/inf-lisp.el (inferior-lisp-mode): Set the needed
    syntax table here, not through other function.
---
 lisp/chistory.el             |  2 +-
 lisp/emacs-lisp/lisp-mode.el | 44 ++++++++++++++++++++++----------------------
 lisp/emacs-lisp/pp.el        |  2 +-
 lisp/files.el                |  3 +++
 lisp/help-fns.el             |  2 +-
 lisp/progmodes/elisp-mode.el | 27 +++++++++------------------
 lisp/progmodes/inf-lisp.el   |  3 ++-
 7 files changed, 39 insertions(+), 44 deletions(-)

diff --git a/lisp/chistory.el b/lisp/chistory.el
index c9aa927..485515d 100644
--- a/lisp/chistory.el
+++ b/lisp/chistory.el
@@ -139,7 +139,7 @@ The buffer is left in Command History mode."
 
 Keybindings:
 \\{command-history-mode-map}"
-  (lisp-mode-variables nil)
+  (lisp-mode-variables)
   (set (make-local-variable 'revert-buffer-function) 'command-history-revert)
   (set-syntax-table emacs-lisp-mode-syntax-table))
 
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 3b0f549..8f7e6c0 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -611,15 +611,8 @@ Value for `adaptive-fill-function'."
   ;; a single docstring.  Let's fix it here.
   (if (looking-at "\\s-+\"[^\n\"]+\"\\s-*$") ""))
 
-(defun lisp-mode-variables (&optional lisp-syntax keywords-case-insensitive
-                                      elisp)
-  "Common initialization routine for lisp modes.
-The LISP-SYNTAX argument is used by code in inf-lisp.el and is
-\(uselessly) passed from pp.el, chistory.el, gnus-kill.el and
-score-mode.el.  KEYWORDS-CASE-INSENSITIVE non-nil means that for
-font-lock keywords will not be case sensitive."
-  (when lisp-syntax
-    (set-syntax-table lisp-mode-syntax-table))
+(defun lisp-mode-variables ()
+  "Common initialization routine for lisp modes."
   (setq-local paragraph-ignore-fill-prefix t)
   (setq-local fill-paragraph-function 'lisp-fill-paragraph)
   (setq-local adaptive-fill-function #'lisp-adaptive-fill)
@@ -643,21 +636,24 @@ font-lock keywords will not be case sensitive."
   (setq-local multibyte-syntax-as-symbol t)
   ;; (setq-local syntax-begin-function 'beginning-of-defun)  ;;Bug#16247.
   (setq font-lock-defaults
-       `(,(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))
-         nil ,keywords-case-insensitive nil nil
-         (font-lock-mark-block-function . mark-defun)
-          (font-lock-extra-managed-props help-echo)
-         (font-lock-syntactic-face-function
-          . lisp-font-lock-syntactic-face-function)))
+       (list nil nil nil nil nil
+              '(font-lock-mark-block-function . mark-defun)
+              '(font-lock-extra-managed-props help-echo)
+              '(font-lock-syntactic-face-function
+                . lisp-font-lock-syntactic-face-function)))
   (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))
 
+;;;###autoload
+(define-derived-mode lisp-data-mode prog-mode "Lisp-Data"
+  "Major mode for buffers holding data written in Lisp syntax."
+  :group 'lisp
+  (lisp-mode-variables)
+  (set-syntax-table lisp-mode-syntax-table)
+  (setq-local electric-quote-string t)
+  (setq imenu-case-fold-search nil))
+
 (defun lisp-outline-level ()
   "Lisp mode `outline-level' function."
   (let ((len (- (match-end 0) (match-beginning 0))))
@@ -737,7 +733,7 @@ font-lock keywords will not be case sensitive."
   "Keymap for ordinary Lisp mode.
 All commands in `lisp-mode-shared-map' are inherited by this map.")
 
-(define-derived-mode lisp-mode prog-mode "Lisp"
+(define-derived-mode lisp-mode lisp-data-mode "Lisp"
   "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.
 Commands:
 Delete converts tabs to spaces as it moves back.
@@ -746,7 +742,11 @@ Blank lines separate paragraphs.  Semicolons start 
comments.
 \\{lisp-mode-map}
 Note that `run-lisp' may be used either to start an inferior Lisp job
 or to switch back to an existing one."
-  (lisp-mode-variables nil t)
+  (setf
+   (nth 0 font-lock-defaults) '(lisp-cl-font-lock-keywords
+                                lisp-cl-font-lock-keywords-1
+                                lisp-cl-font-lock-keywords-2)
+   (nth 2 font-lock-defaults) t)
   (setq-local lisp-indent-function 'common-lisp-indent-function)
   (setq-local find-tag-default-function 'lisp-find-tag-default)
   (setq-local comment-start-skip
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index 3df7b0e..4d8bf52 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -42,7 +42,7 @@
 OBJECT can be any Lisp object.  Quoting characters are used as needed
 to make output that `read' can handle, whenever this is possible."
   (with-temp-buffer
-    (lisp-mode-variables nil)
+    (lisp-mode-variables)
     (set-syntax-table emacs-lisp-mode-syntax-table)
     (let ((print-escape-newlines pp-escape-newlines)
           (print-quoted t))
diff --git a/lisp/files.el b/lisp/files.el
index fa72e51..a769d06 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2657,6 +2657,9 @@ since only a single case-insensitive search through the 
alist is made."
      ("\\.ltx\\'" . latex-mode)
      ("\\.dtx\\'" . doctex-mode)
      ("\\.org\\'" . org-mode)
+     ;; .dir-locals.el is not really elisp.  Can't use the
+     ;; `dir-locals-file' constant since that is defined below.
+     (".dir-locals.el" . lisp-data-mode)
      ("\\.el\\'" . emacs-lisp-mode)
      ("Project\\.ede\\'" . emacs-lisp-mode)
      ("\\.\\(scm\\|stk\\|ss\\|sch\\)\\'" . scheme-mode)
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 0a99b8d..dbf2cb8 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -1000,7 +1000,7 @@ it is displayed along with the global value."
                    (terpri)
                     (let ((buf (current-buffer)))
                       (with-temp-buffer
-                        (lisp-mode-variables nil)
+                        (lisp-mode-variables)
                         (set-syntax-table emacs-lisp-mode-syntax-table)
                         (insert print-rep)
                         (pp-buffer)
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index f85fd77..2f23178 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -250,7 +250,7 @@ Comments in the form will be lost."
     map))
 
 ;;;###autoload
-(define-derived-mode emacs-lisp-mode prog-mode
+(define-derived-mode emacs-lisp-mode lisp-data-mode
   `("ELisp"
     (lexical-binding (:propertize "/l"
                       help-echo "Using lexical-binding mode")
@@ -268,35 +268,26 @@ Blank lines separate paragraphs.  Semicolons start 
comments.
 \\{emacs-lisp-mode-map}"
   :group 'lisp
   (defvar project-vc-external-roots-function)
-  (lisp-mode-variables nil nil 'elisp)
+  (setcar font-lock-defaults
+          '(lisp-el-font-lock-keywords
+            lisp-el-font-lock-keywords-1
+            lisp-el-font-lock-keywords-2))
+  (set-syntax-table emacs-lisp-mode-syntax-table)
   (add-hook 'after-load-functions #'elisp--font-lock-flush-elisp-buffers)
   (if (boundp 'electric-pair-text-pairs)
       (setq-local electric-pair-text-pairs
                   (append '((?\` . ?\') (?\‘ . ?\’))
                           electric-pair-text-pairs))
     (add-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs))
-  (setq-local electric-quote-string t)
-  (setq imenu-case-fold-search nil)
   (add-hook 'eldoc-documentation-functions
             #'elisp-eldoc-documentation-function nil t)
   (add-hook 'xref-backend-functions #'elisp--xref-backend nil t)
   (setq-local project-vc-external-roots-function #'elisp-load-path-roots)
   (add-hook 'completion-at-point-functions
             #'elisp-completion-at-point nil 'local)
-  ;; .dir-locals.el and lock files will cause the byte-compiler and
-  ;; checkdoc emit spurious warnings, because they don't follow the
-  ;; conventions of Emacs Lisp sources.  Until we have a better fix,
-  ;; like teaching elisp-mode about files that only hold data
-  ;; structures, we disable the ELisp Flymake backend for these files.
-  (unless
-      (let* ((bfname (buffer-file-name))
-             (fname (and (stringp bfname) (file-name-nondirectory bfname))))
-        (and (stringp fname)
-             (or (string-match "\\`\\.#" fname)
-                 (string-equal dir-locals-file fname))))
-    (add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t)
-    (add-hook 'flymake-diagnostic-functions
-              #'elisp-flymake-byte-compile nil t)))
+  (add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t)
+  (add-hook 'flymake-diagnostic-functions
+              #'elisp-flymake-byte-compile nil t))
 
 ;; Font-locking support.
 
diff --git a/lisp/progmodes/inf-lisp.el b/lisp/progmodes/inf-lisp.el
index 9f34a37..aa6c718 100644
--- a/lisp/progmodes/inf-lisp.el
+++ b/lisp/progmodes/inf-lisp.el
@@ -274,7 +274,8 @@ If you accidentally suspend your process, use 
\\[comint-continue-subjob]
 to continue it."
   (setq comint-prompt-regexp inferior-lisp-prompt)
   (setq mode-line-process '(":%s"))
-  (lisp-mode-variables t)
+  (set-syntax-table lisp-mode-syntax-table)
+  (lisp-mode-variables)
   (setq comint-get-old-input (function lisp-get-old-input))
   (setq comint-input-filter (function lisp-input-filter)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]