[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)))
- [nongnu] elpa/lua-mode fa1ef23 107/468: lua-mode-map: dont evaluate at compile-time (fix byte-compilation error), (continued)
- [nongnu] elpa/lua-mode fa1ef23 107/468: lua-mode-map: dont evaluate at compile-time (fix byte-compilation error), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e9a17ba 120/468: Added autoload for (add-to-list 'interpreter-mode-alist '("lua" . lua-mode)), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 509700f 130/468: lua--automark-update-start-pos: rewind to beginning of line to make sure newly inserted multiline literal delimiters are recognized, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 066d042 139/468: Merge pull request #12 from vhallac/vh-indentation-mods, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 39cf29e 141/468: Whoops! Add missing parenthesis, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 66cd58a 171/468: Fix test_indentation.sh, add basic_blocks.lua indentation test, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4b27305 097/468: Add safe default target to makefile, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ddcd8b8 102/468: Makefile: specify dist contents explicitly, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode aa10440 148/468: Bump TODO, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8638475 174/468: Fix use of flet for Emacs > 24.1, and enable assert., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f926323 180/468: Extend and unify backward compatibility code,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 6245e50 190/468: Add helper functions for reimplementation of font-lock-keywords, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 40c00bf 189/468: lua-font-lock-keywords: fontify constants/builtins first, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3a3f0b0 193/468: Improve local var assignment matching, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode af50eca 195/468: Bump copyright information (no luck with FSF), rephrase comment, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 918f297 072/468: rename: lua-calculate-indentation-left-shift -> lua-calculate-unindentation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cf2f42a 076/468: .gitignore: ignore emacs backups, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9384855 093/468: lua-mark-all-multiline-literals: run when during lua-mode initialization, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6de08c0 090/468: Update TODO, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e3a8282 099/468: Make URL/Version fields in lua-mode.el prettier, update parse expression in Makefile, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1c37d0d 114/468: Bump version, Philip Kaludercic, 2021/08/05