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

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

[nongnu] elpa/lua-mode f926323 180/468: Extend and unify backward compat


From: Philip Kaludercic
Subject: [nongnu] elpa/lua-mode f926323 180/468: Extend and unify backward compatibility code
Date: Thu, 5 Aug 2021 04:58:32 -0400 (EDT)

branch: elpa/lua-mode
commit f926323f643a8b21c4f86919ad07ebb0e336f3a4
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>

    Extend and unify backward compatibility code
---
 lua-mode.el | 94 +++++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 67 insertions(+), 27 deletions(-)

diff --git a/lua-mode.el b/lua-mode.el
index b8b7e5f..f300c4f 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -105,8 +105,8 @@
 
 (require 'comint)
 
-;; Backward compatibility for Emacsen < 24.1
 (eval-and-compile
+  ;; Backward compatibility for Emacsen < 24.1
   (defalias 'lua--prog-mode
     (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
 
@@ -114,7 +114,66 @@
     (if (fboundp 'cl-assert) 'cl-assert 'assert))
 
   (defalias 'lua--cl-labels
-    (if (fboundp 'cl-labels) 'cl-labels 'flet)))
+    (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
@@ -1203,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 ()
@@ -1434,33 +1493,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.
@@ -1501,10 +1541,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.
@@ -1525,7 +1565,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]