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

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

[nongnu] elpa/lua-mode 08ff6ea 183/468: Merge remote-tracking branch 'or


From: Philip Kaludercic
Subject: [nongnu] elpa/lua-mode 08ff6ea 183/468: Merge remote-tracking branch 'origin/master'
Date: Thu, 5 Aug 2021 04:58:32 -0400 (EDT)

branch: elpa/lua-mode
commit 08ff6ea4740a4ce9d5d7a836147f560f3e8d3299
Merge: b9541ce e6a46ee
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>

    Merge remote-tracking branch 'origin/master'
---
 README.md   |  31 ++++++++++--
 lua-mode.el | 162 ++++++++++++++++++++++++++++++++++++++----------------------
 2 files changed, 130 insertions(+), 63 deletions(-)

diff --git a/README.md b/README.md
index 3dc9bd2..9b2d6ef 100644
--- a/README.md
+++ b/README.md
@@ -6,17 +6,38 @@ If you have a problem or a suggestion about **lua-mode**, 
please, let me know ab
 
 ## INSTALLATION
 
-To install, just copy `lua-mode.el` into a directory on your load-path (and 
optionally byte-compile it).
-To set up Emacs to automatically edit files ending in `.lua` or with a lua 
hash-bang line using **lua-mode**
-add the following to your init file:
+### EL-GET INSTALLATION
+
+[El-get](https://github.com/dimitri/el-get) is a package manager which greatly 
simplifies adding
+modules to your Emacs and keeping them up-to-date. Once you have **el-get** 
set up, installing
+**lua-mode** can be done with
+
+    <M-x> el-get-install "lua-mode"
+
+and updating is no more than
+
+    <M-x> el-get-update "lua-mode"`
+    
+Please, consult with [el-get 
documentation](https://github.com/dimitri/el-get/blob/master/README.md) for 
further information.
+
+### MANUAL INSTALLATION
+
+To install, you need to make sure that `lua-mode.el` is on your load-path (and 
optionally byte-compile
+it) and to set up Emacs to automatically enable **lua-mode** for `*.lua` files 
or ones that contain lua
+hash-bang line (`#!/usr/bin/lua`). Putting this snippet to `.emacs` should be 
enough in most cases:
+```lisp
+    ;;;; This snippet enables lua-mode
+
+    ;; This line is not necessary, if lua-mode.el is already on your load-path
+    (add-to-list 'load-path "/path/to/directory/where/lua-mode-el/resides")
 
     (autoload 'lua-mode "lua-mode" "Lua editing mode." t)
     (add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
     (add-to-list 'interpreter-mode-alist '("lua" . lua-mode))
-
+```
 ## USAGE
 
-**lua-mode** supports c-mode style formatting and sending of 
lines/regions/files to a Lua interpreter. An
+**lua-mode** supports some formatting and sending of lines/regions/files to a 
Lua interpreter. An
 interpreter (see variable `lua-default-application`) will be started if you 
try to send some code and none
 is running. You can use the process-buffer (named after the application you 
chose) as if it were an
 interactive shell. See the documentation for `comint.el` for details.
diff --git a/lua-mode.el b/lua-mode.el
index ef28a04..54585bf 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -105,6 +105,76 @@
 
 (require 'comint)
 
+(eval-and-compile
+  ;; Backward compatibility for Emacsen < 24.1
+  (defalias 'lua--prog-mode
+    (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
+
+  (defalias 'lua--cl-assert
+    (if (fboundp 'cl-assert) 'cl-assert 'assert))
+
+  (defalias 'lua--cl-labels
+    (if (fboundp 'cl-labels) 'cl-labels 'flet))
+
+  ;; for Emacsen < 22.1
+  (defalias 'lua--with-no-warnings
+    (if (fboundp 'with-no-warnings) 'with-no-warnings 'progn))
+
+  ;; provide backward compatibility for Emacs < 23.2
+  ;; called-interactively-p receives an argument starting from Emacs 23.2
+  ;; In Emacs 22 & Emacs 23.1 it didn't expect an argument
+  ;; In Emacs 21 it was called interactively-p
+  (condition-case nil
+      (progn (called-interactively-p nil)
+             ;; if first call succeeds, make lua-called-interactively-p an 
alias
+             (defalias 'lua--called-interactively-p 'called-interactively-p))
+
+    (wrong-number-of-arguments
+     ;; wrong number of arguments means it's 22.1 <= Emacs < 23.2
+     ;;
+     ;; Newer and smarter Emacsen will warn about obsolete functions
+     ;; and/or wrong number of arguments. Turning these warnings off,
+     ;; since it's backward-compatibility-oriented code anyway.
+     (lua--with-no-warnings
+       (defun lua--called-interactively-p (kind)
+         "Return t if containing function was called interactively.
+
+This function provides lua-mode backward compatibility for
+pre-23.2 Emacsen."
+         (if (eq kind 'interactive)
+             (interactive-p)
+           (called-interactively-p)))))
+
+    ;; if not, it's probably < 22.1, provide partial compatibility
+    ;;
+    ;; Once again, turning obsolete-function warnings off (see above).
+    (error
+     (lua--with-no-warnings
+       (defun lua--called-interactively-p (&rest opts)
+         "Return t if containing function was called interactively.
+
+This function provides lua-mode backward compatibility for pre-22
+Emacsen."
+         (interactive-p)))))
+
+  ;; backward compatibility for Emacsen < 23.3
+  ;; Emacs 23.3 introduced with-silent-modifications macro
+  (if (fboundp 'with-silent-modifications)
+      (defalias 'lua--with-silent-modifications 'with-silent-modifications)
+
+    (defmacro lua--with-silent-modifications (&rest body)
+      "Execute BODY, pretending it does not modifies the buffer.
+
+This is a reimplementation of macro `with-silent-modifications'
+for Emacsen that doesn't contain one (pre-23.3)."
+      `(let ((old-modified-p (buffer-modified-p))
+            (inhibit-modification-hooks t)
+            (buffer-undo-list t))
+
+        (unwind-protect
+            ,@body
+          (set-buffer-modified-p old-modified-p))))))
+
 ;; Local variables
 (defgroup lua nil
   "Major mode for editing lua code."
@@ -154,8 +224,7 @@ Should be a list of strings."
   "Buffer used for communication with Lua subprocess")
 
 (defun lua--customize-set-prefix-key (prefix-key-sym prefix-key-val)
-  ;; FIXME: enable assertion, it requires 'cl and I'm not sure of its 
availability
-  ;; (assert (eq prefix-key-sym 'lua-prefix-key))
+  (lua--cl-assert (eq prefix-key-sym 'lua-prefix-key))
   (set prefix-key-sym (if (and prefix-key-val (> (length prefix-key-val) 0))
                           ;; read-kbd-macro returns a string or a vector
                           ;; in both cases (elt x 0) is ok
@@ -308,7 +377,7 @@ traceback location."
       ;; makes sense to me, I'm going to wipe them out as soon as I'm sure
       ;; that indentation won't get hurt. --immerrr
       ;;
-      (flet
+      (lua--cl-labels
           ((module-name-re (x)
                            (concat "\\(?1:\\<"
                                    (if (listp x) (car x) x)
@@ -422,18 +491,34 @@ index of respective Lua reference manuals.")
              (temp-directory)
            temporary-file-directory))))))
 
+(defvar lua-mode-syntax-table
+  (with-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 ?\" "\"")
+    (syntax-table))
+  "Syntax table used while in `lua-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 lua--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 +532,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 +557,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))
@@ -1197,7 +1262,7 @@ When called interactively, switch to the process buffer."
       (accept-process-output (get-buffer-process (current-buffer)))
       (goto-char (point-max))))
   ;; when called interactively, switch to process buffer
-  (if (called-interactively-p 'any)
+  (if (lua--called-interactively-p 'any)
       (switch-to-buffer lua-process-buffer)))
 
 (defun lua-kill-process ()
@@ -1435,33 +1500,14 @@ left out."
 (define-key lua-mode-menu [search-documentation]
   '("Search Documentation" . lua-search-documentation))
 
-(eval-and-compile
-  ;; Emacs 23.3 introduced with-silent-modifications macro
-  ;; use it if it's available, otherwise define a replacement for that
-  (if (fboundp 'with-silent-modifications)
-      (defalias 'lua-with-silent-modifications 'with-silent-modifications)
-
-    (defmacro lua-with-silent-modifications (&rest body)
-      "Execute BODY, pretending it does not modifies the buffer.
-
-This is a reimplementation of macro `with-silent-modifications'
-for Emacsen that doesn't contain one (pre-23.3)."
-      `(let ((old-modified-p (buffer-modified-p))
-            (inhibit-modification-hooks t)
-            (buffer-undo-list t))
-
-        (unwind-protect
-            ,@body
-          (set-buffer-modified-p old-modified-p))))))
-
 (defsubst lua-put-char-property (pos property value &optional object)
-  (lua-with-silent-modifications
+  (lua--with-silent-modifications
 
    (if value
        (put-text-property pos (1+ pos) property value object)
      (remove-text-properties pos (1+ pos) (list property nil))))
 
-  ;; `lua-with-silent-modifications' inhibits modification hooks, one of which
+  ;; `lua--with-silent-modifications' inhibits modification hooks, one of which
   ;; is the hook that keeps `syntax-ppss' internal cache up-to-date. If this
   ;; isn't done, the results of subsequent calls to `syntax-ppss' are
   ;; invalid. To avoid such cache discrepancy, the hook must be run manually.
@@ -1502,10 +1548,10 @@ If END is nil, stop at `end-of-buffer'."
   (setq begin (or begin (point-min))
         end   (or end   (point-max)))
 
-  (lua-with-silent-modifications
+  (lua--with-silent-modifications
    (remove-text-properties begin end '(syntax-table ())))
 
-  ;; `lua-with-silent-modifications' inhibits modification hooks, one of which
+  ;; `lua--with-silent-modifications' inhibits modification hooks, one of which
   ;; is the hook that keeps `syntax-ppss' internal cache up-to-date. If this
   ;; isn't done, the results of subsequent calls to `syntax-ppss' are
   ;; invalid. To avoid such cache discrepancy, the hook must be run manually.
@@ -1526,7 +1572,7 @@ If BEGIN is nil, start from `beginning-of-buffer'.
 If END is nil, stop at `end-of-buffer'."
   (interactive)
 
-  (if (and (called-interactively-p 'any) (use-region-p))
+  (if (and (lua--called-interactively-p 'any) (use-region-p))
       (setq begin (region-beginning)
             end (region-end)))
 



reply via email to

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