From 417e7d236284bbe02864f1905f65b77c959813d5 Mon Sep 17 00:00:00 2001 From: Akib Azmain Turja Date: Thu, 19 Jan 2023 15:45:44 +0600 Subject: [PATCH] Auto reload Eat when "semi-char" map is customized * eat.el (eat--load-file-path, eat--being-loaded): New variable. * eat.el (eat-semi-char-non-bound-keys) (eat-eshell-semi-char-non-bound-keys): Reload Eat when customized. Document what to do if changed from Lisp. * eat.el (eat-update-semi-char-mode-map) (eat-eshell-update-semi-char-mode-map): New function. * eat.el (eat-reload): New command. * eat.texi (Semi-char Mode): Document what to do if the lists of not bound keys are changed from Lisp. --- eat.el | 63 ++++++++++++++++++++++++++++++++++++++++++++++---------- eat.texi | 9 ++++++++ 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/eat.el b/eat.el index 35a78cf..010706c 100644 --- a/eat.el +++ b/eat.el @@ -83,6 +83,12 @@ (require 'shell) (require 'url) +;; Needed by `eat-reload'. +(defvar eat--being-loaded nil + "Non-nil means Eat is being loaded.") + +(setq eat--being-loaded t) + ;;;; User Options. @@ -167,13 +173,18 @@ Eat might still bound them to do something else (for example, changing keybinding mode). Each element is a vector of form [KEY] or [?\\e KEY], meaning KEY or -M-KEY shouldn't be bound. KEY shouldn't contain meta (Alt) modifier." +M-KEY shouldn't be bound. KEY shouldn't contain meta (Alt) modifier. + +When changing this from Lisp, make sure to call +`eat-update-semi-char-mode-map' to update the keymap and reload Eat to +make the changes effective." :type '(repeat sexp) :set (lambda (sym val) (set-default-toplevel-value sym val) - (when (boundp 'eat-semi-char-mode-map) - (setq eat-semi-char-mode-map - (eat--prepare-semi-char-mode-map)))) + (when (and (not eat--being-loaded) + (boundp 'eat-semi-char-mode-map)) + (eat-update-semi-char-mode-map) + (eat-reload))) :group 'eat-ui) (defcustom eat-eshell-semi-char-non-bound-keys @@ -186,13 +197,18 @@ Eat might still bound them to do something else (for example, changing keybinding mode). Each element is a vector of form [KEY] or [?\\e KEY], meaning KEY or -M-KEY shouldn't be bound. KEY shouldn't contain meta (Alt) modifier." +M-KEY shouldn't be bound. KEY shouldn't contain meta (Alt) modifier. + +When changing this from Lisp, make sure to call +`eat-eshell-update-semi-char-mode-map' to update the keymap and reload +Eat to make the changes effective." :type '(repeat sexp) :set (lambda (sym val) (set-default-toplevel-value sym val) - (when (boundp 'eat-eshell-semi-char-mode-map) - (setq eat-eshell-semi-char-mode-map - (eat--eshell-prepare-semi-char-mode-map)))) + (when (and (not eat--being-loaded) + (boundp 'eat-eshell-semi-char-mode-map)) + (eat-eshell-update-semi-char-mode-map) + (eat-reload))) :group 'eat-eshell) (defcustom eat-enable-directory-tracking t @@ -384,6 +400,9 @@ This value is used by terminal programs to identify the terminal." ;; Upgrading Eat causes `eat-term-terminfo-directory' and ;; `eat-term-shell-integration-directory' to be outdated, so update it ;; if not modified by user (or something else). +(defvar eat--load-file-path nil + "Path to currently loaded Eat.") + (defvar eat--install-path nil "Path to directory where Eat is installed.") @@ -393,9 +412,10 @@ This value is used by terminal programs to identify the terminal." (defvar eat--shell-integration-path nil "Path to directory where shell integration scripts are installed.") +(setq eat--load-file-path (or load-file-name buffer-file-name)) + (setq eat--install-path - (copy-sequence (file-name-directory - (or load-file-name buffer-file-name)))) + (copy-sequence (file-name-directory eat--load-file-path))) (defvar eat-term-terminfo-directory) (defvar eat-term-shell-integration-directory) @@ -4835,7 +4855,7 @@ STRING and ARG are passed to `yank-pop', which see." "Handle paste operation EVENT from XTerm." (interactive "e") (unless (eq (car-safe event) 'xterm-paste) - (error "xterm-paste must be found to xterm-paste event")) + (error "`eat-xterm-paste' must be bind to `xterm-paste' event")) (let ((pasted-text (nth 1 event))) (if (bound-and-true-p xterm-store-paste-on-kill-ring) ;; Put the text onto the kill ring and then insert it into the @@ -4877,6 +4897,10 @@ STRING and ARG are passed to `yank-pop', which see." (eat--prepare-semi-char-mode-map)) "Keymap for Eat semi-char mode.") +(defun eat-update-semi-char-mode-map () + "Update \"semi-char\" keybinding mode's keymap." + (setq eat-semi-char-mode-map (eat--prepare-semi-char-mode-map))) + (defvar eat-char-mode-map (let ((map (eat-term-make-keymap #'eat-self-input '(:ascii :arrow :navigation :function) @@ -5519,6 +5543,11 @@ PROGRAM can be a shell command." (eat--eshell-prepare-semi-char-mode-map)) "Keymap for Eat Eshell semi-char mode.") +(defun eat-eshell-update-semi-char-mode-map () + "Update \"semi-char\" keybinding mode's keymap in Eshell." + (setq eat-eshell-semi-char-mode-map + (eat--eshell-prepare-semi-char-mode-map))) + (defvar eat-eshell-char-mode-map (let ((map (eat-term-make-keymap #'eat-self-input '(:ascii :arrow :navigation :function) @@ -6504,5 +6533,17 @@ N defaults to 1. Interactively, N is the prefix argument." "]")) (add-hook 'kill-buffer-hook #'eat-trace--cleanup nil t)) + +;;;; Footer. + +(defun eat-reload () + "Reload Eat." + (interactive) + (unless eat--being-loaded + ;; Remove .elc suffix to load native compiled version if possible. + (load (string-remove-suffix ".elc" eat--load-file-path)))) + +(setq eat--being-loaded nil) + (provide 'eat) ;;; eat.el ends here diff --git a/eat.texi b/eat.texi index 885aecd..7fa83f7 100644 --- a/eat.texi +++ b/eat.texi @@ -294,6 +294,15 @@ modifier. To not bind a key with meta modifier, use a vector of form @code{[?\e @var{key}]}, where @var{key} is the key without meta modifier. +@findex eat-update-semi-char-mode-map +@findex eat-eshell-update-semi-char-mode-map +@findex eat-reload +If you set the user options manually (for example, with @code{setq}), +you must call @code{eat-update-semi-char-mode-map} or +@code{eat-eshell-update-semi-char-mode-map} respectively, and finally +reload Eat (you can do this with the command @command{eat-reload}). +Or alternatively you can set the user options before Eat is loaded. + @anchor{Char Mode} @cindex char mode @cindex mode, char