emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/lua-mode c2f8a7f 175/468: Use define-derived-mode


From: Philip Kaludercic
Subject: [nongnu] elpa/lua-mode c2f8a7f 175/468: Use define-derived-mode
Date: Thu, 5 Aug 2021 04:58:31 -0400 (EDT)

branch: elpa/lua-mode
commit c2f8a7f8a5948de985b42a2e02dbd08bad2b605a
Author: Julien Danjou <julien@danjou.info>
Commit: Julien Danjou <julien@danjou.info>

    Use define-derived-mode
    
    This allows to inherit from `prog-mode', which is very convenient. It also
    simplifies the declaration, and do not recreate the syntax table on each
    lua-mode call.
    
    Signed-off-by: Julien Danjou <julien@danjou.info>
---
 lua-mode.el | 59 +++++++++++++++++++++++++++++------------------------------
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/lua-mode.el b/lua-mode.el
index 4f79e82..d8588ae 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -422,18 +422,37 @@ index of respective Lua reference manuals.")
              (temp-directory)
            temporary-file-directory))))))
 
+(defvar lua-mode-syntax-table
+  (let ((st (copy-syntax-table)))
+    (modify-syntax-entry ?+ ".")
+    (modify-syntax-entry ?- ". 12")
+    (modify-syntax-entry ?* ".")
+    (modify-syntax-entry ?/ ".")
+    (modify-syntax-entry ?^ ".")
+    ;; This might be better as punctuation, as for C, but this way you
+    ;; can treat table index as symbol.
+    (modify-syntax-entry ?. "_")        ; e.g. `io.string'
+    (modify-syntax-entry ?> ".")
+    (modify-syntax-entry ?< ".")
+    (modify-syntax-entry ?= ".")
+    (modify-syntax-entry ?~ ".")
+    (modify-syntax-entry ?\n ">")
+    (modify-syntax-entry ?\' "\"")
+    (modify-syntax-entry ?\" "\""))
+  "Syntax table used while in `lua-mode'.")
+
+;; For Emacs < 24.1
+(unless (fboundp 'prog-mode)
+  (defalias 'prog-mode 'fundamental-mode))
+
 ;;;###autoload
-(defun lua-mode ()
-  "Major mode for editing Lua code.
-The following keys are bound:
-\\{lua-mode-map}
-"
-  (interactive)
+(define-derived-mode lua-mode prog-mode "Lua"
+  "Major mode for editing Lua code."
+  :abbrev-table lua-mode-abbrev-table
+  :syntax-table lua-mode-syntax-table
+  :group 'lua
   (let ((switches nil)
         s)
-    (kill-all-local-variables)
-    (setq major-mode 'lua-mode)
-    (setq mode-name "Lua")
     (setq comint-prompt-regexp lua-prompt-regexp)
     (make-local-variable 'lua-default-command-switches)
     (set (make-local-variable 'beginning-of-defun-function)
@@ -447,26 +466,7 @@ The following keys are bound:
            nil nil ((?_ . "w"))))
     (set (make-local-variable 'imenu-generic-expression)
          lua-imenu-generic-expression)
-    (setq local-abbrev-table lua-mode-abbrev-table)
-    (abbrev-mode 1)
     (make-local-variable 'lua-default-eval)
-    (use-local-map lua-mode-map)
-    (set-syntax-table (copy-syntax-table))
-    (modify-syntax-entry ?+ ".")
-    (modify-syntax-entry ?- ". 12")
-    (modify-syntax-entry ?* ".")
-    (modify-syntax-entry ?/ ".")
-    (modify-syntax-entry ?^ ".")
-    ;; This might be better as punctuation, as for C, but this way you
-    ;; can treat table index as symbol.
-    (modify-syntax-entry ?. "_")        ; e.g. `io.string'
-    (modify-syntax-entry ?> ".")
-    (modify-syntax-entry ?< ".")
-    (modify-syntax-entry ?= ".")
-    (modify-syntax-entry ?~ ".")
-    (modify-syntax-entry ?\n ">")
-    (modify-syntax-entry ?\' "\"")
-    (modify-syntax-entry ?\" "\"")
     ;; setup menu bar entry (XEmacs style)
     (if (and (featurep 'menubar)
              (boundp 'current-menubar)
@@ -491,8 +491,7 @@ The following keys are bound:
 
     (set (make-local-variable 'parse-sexp-lookup-properties) t)
     (lua-mark-all-multiline-literals)
-    (lua--automark-multiline-update-timer)
-    (run-hooks 'lua-mode-hook)))
+    (lua--automark-multiline-update-timer)))
 
 ;;;###autoload
 (add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))



reply via email to

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