[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 3339da6 067/468: lua-prefix-key: auto-convert fro
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 3339da6 067/468: lua-prefix-key: auto-convert from/to character, update bindings automagically |
Date: |
Thu, 5 Aug 2021 04:58:09 -0400 (EDT) |
branch: elpa/lua-mode
commit 3339da69af59a9a8d0d5a608c1a214cb7d81e1b8
Author: immerrr <immerrr@gmail.com>
Commit: immerrr <immerrr@gmail.com>
lua-prefix-key: auto-convert from/to character, update bindings
automagically
---
lua-mode.el | 45 +++++++++++++++++++++++++++++++++++++++++----
1 file changed, 41 insertions(+), 4 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 70a39a4..32a8d2d 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -135,10 +135,25 @@ Should be a list of strings."
(defvar lua-process-buffer nil
"Buffer used for communication with Lua subprocess")
+;; defined later on, for now - nothing to update anyways
+(defun lua-prefix-key-update-bindings ()
+ )
+
+(defun lua--customize-set-prefix-key (prefix-key-sym prefix-key-val)
+ (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
+ (elt (read-kbd-macro prefix-key-val) 0)))
+ (lua-prefix-key-update-bindings)
+ (message "prefix key set to %S" prefix-key-sym))
+
(defcustom lua-prefix-key "\C-c"
"Prefix for all lua-mode commands."
:type 'string
- :group 'lua)
+ :group 'lua
+ :set 'lua--customize-set-prefix-key
+ :get '(lambda (sym)
+ (let ((val (eval sym))) (if val (single-key-description (eval sym))
""))))
(defvar lua-mode-menu (make-sparse-keymap "Lua")
"Keymap for lua-mode's menu.")
@@ -158,7 +173,7 @@ If the latter is nil, the keymap translates into
`lua-mode-map' verbatim.")
(defvar lua-mode-map
(eval-when-compile
(let ((result-map (make-sparse-keymap))
- (prefix-key (if (boundp 'lua-prefix-key) lua-prefix-key)))
+ prefix-key)
(mapc (lambda (key_defn)
(define-key result-map (read-kbd-macro (car key_defn)) (cdr
key_defn)))
;; here go all the default bindings
@@ -176,8 +191,8 @@ If the latter is nil, the keymap translates into
`lua-mode-map' verbatim.")
;; * if no prefix, set prefix-map as parent, i.e.
;; if key is not defined look it up in prefix-map
;; * if prefix is set, bind the prefix-map to that key
- (if lua-prefix-key
- (define-key result-map lua-prefix-key lua-prefix-mode-map)
+ (if (boundp 'lua-prefix-key)
+ (define-key result-map (vector lua-prefix-key) lua-prefix-mode-map)
(set-keymap-parent result-map lua-prefix-mode-map))
result-map))
"Keymap used in lua-mode buffers.")
@@ -367,6 +382,28 @@ The following keys are bound:
(blink-matching-open))
;; private functions
+
+(defun lua-prefix-key-update-bindings ()
+ (let (old-cons)
+ (if (eq lua-prefix-mode-map (keymap-parent lua-mode-map))
+ ;; if prefix-map is a parent, delete the parent
+ (set-keymap-parent lua-mode-map nil)
+ ;; otherwise, look for it among children
+ (if (setq old-cons (rassoc lua-prefix-mode-map lua-mode-map))
+ (delq old-cons lua-mode-map)))
+
+ (if (null lua-prefix-key)
+ (set-keymap-parent lua-mode-map lua-prefix-mode-map)
+ (define-key lua-mode-map (vector lua-prefix-key) lua-prefix-mode-map))))
+
+(defun lua-set-prefix-key (new-key-str)
+ "Changes `lua-prefix-key' properly and updates keymaps
+
+This function replaces previous prefix-key binding with a new one."
+ (interactive "sNew prefix key (empty string means no key): ")
+ (lua--customize-set-prefix-key 'lua-prefix-key new-key-str)
+ (lua-prefix-key-update-bindings))
+
(defun lua-syntax-status ()
"Returns the syntactic status of the character after the point."
(parse-partial-sexp (line-beginning-position) (point)))
- [nongnu] elpa/lua-mode a5f8e7b 048/468: Fix generation and use of VERSION, and ignore release notes files., (continued)
- [nongnu] elpa/lua-mode a5f8e7b 048/468: Fix generation and use of VERSION, and ignore release notes files., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 14300f1 049/468: Specify branch to pull from., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 60073cc 050/468: Change https to http in URL., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7af5dec 057/468: Use line-beginning(-end)-position when possible, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3ba5bf1 059/468: Redo lua-toggle-electric-state, remove extra function lua-calculate-state, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode e610db4 060/468: lua-make-indentation-info-pair: readability refactoring, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cc46763 061/468: Add some comments, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b2860f1 062/468: lua-setup-keymap: improve readability, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7935b5f 064/468: Fix previous commit, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 85d26f8 065/468: lua-mode-map: initialize as soon as lua-mode is loaded (previously waited for call to lua-mode), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3339da6 067/468: lua-prefix-key: auto-convert from/to character, update bindings automagically,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 5842703 068/468: Add TODO, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8165775 069/468: Fix lua-set-prefix message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6b1d389 074/468: lua-calculate-unindentation: skip semicolons as well, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bda4fbd 075/468: lua-calculate-unindentation: update docs, remove extraneous catch, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a20b08e 078/468: lua-indent-line: remove extra variable shift-amt, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c0d6f80 079/468: Add markdown README, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 08cff6e 081/468: Implement basic multiline-aware functionality, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode dfc3b78 083/468: Preserve buffer-modified-p state when (un-)marking multiline delimiters, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7920d17 087/468: lua-mark-all-multiline-literals: if region is active, limit to region boundaries, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4a22b3c 100/468: Allow lua-start-process to be called interactively., Philip Kaludercic, 2021/08/05