branch: scratch/ergoemacs-mode commit 53bd030bdffced40cb43f12818a4598bef80c5f9 Author: Stefan Monnier <monn...@iro.umontreal.ca> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Remove some dead code and address various compiler warnings The original goal was to remove the remaining use of `defadvice` (in `ergoemacs-advice`) but that proved to be dead code, and then I checked the resulting compiler warnings, etc... Prefer #' to quote function names. Remove dummy `unwind-protect` without any unwind forms. Avoid deprecated `point-at-bol/eol`. Fix some uses of ' in docstrings. Also fix a misunderstanding: `inhibit-point-motion-hooks` is not used by the command loop's point adjustment code, it's only used by the low-level point-motion hooks (those implemented deep inside the C code of `goto-char` and friends, and which have been deprecated since Emacs-25 because running arbitrary ELisp code from within `goto-char` is too problematic). * ergoemacs-macros.el (ergoemacs-save-buffer-state): Make it an obsolete alias of `with-silent-modifications`. Update all callers. (ergoemacs-translation): Simplify `kb` initialization and remove unneeded `progn`. (ergoemacs-advice): Delete unused macro. * ergoemacs-theme-engine.el (ergoemacs-describe-key): Fix typo. * ergoemacs-layouts.el: Fix typo in the `lexical-binding` cookie. (ergoemacs-layout--regexp): Remove unused var `reg`. (ergoemacs-layout-describe): Remove unused vars `alias` and `pt`. * ergoemacs-test.el: Require packages, to reduce compiler warnings. (<toplevel>): Don't quote `lambda`; don't let-bind unused `ergoemacs-is-user-defined-map-change-p`; and don't specify `interactive` for a function only used on a hook. (ergoemacs-use-function-remapping): Declare var as dynamic. (ergoemacs-test): Remove unused var `ret` and `test`. (ergoemacs-test-ignore-ctl-w): Remove unused var `ret`. (ergoemacs-test--dired-sort-map): New var extracted from `ergoemacs-test-dired-sort-files`. (ergoemacs-test--dired-hook): New function extracted from `ergoemacs-test-dired-sort-files`. (ergoemacs-test-dired-sort-files): Use them to simplify the code by reducing duplication. * ergoemacs-mode.el (ergoemacs-mode): Remove spurious `nil` arg before the keyword arguments. (ergoemacs-setup-override-keymap): Don't abuse `add-hook` on a non-hook. (ergoemacs-remove-override-keymap): Don't abuse `remove-hook` on a non-hook. * ergoemacs-mapkeymap.el (ergoemacs-map-keymap): Remove unused/constant var `calc-parent-p`. * ergoemacs-map.el (ergoemacs-map--alist): Merge two `prog1`. * ergoemacs-functions.el (ergoemacs-delete-char): Delete one of the two duplicate definitions. (ergoemacs-run-clean): Remove unused/constant `rm-batch` variable and associated dead code. Use `derived-mode-p`. (ergoemacs-use-beginning-or-end-of-line-only): Fix wrong `const` format in the `:type`. (ergoemacs-beginning-of-line-or-what): `beginning-of-buffer` is for interactive use only. (ergoemacs-maximum-number-of-file-to-open): Fix typo in `:type`. (ergoemacs-camelize-method): Don't quote `lambda`. * ergoemacs-command-loop.el (ergoemacs-command-loop--decode-event): Comment out unused var `timeout-key`. (ergoemacs-command-loop--point-motion-hooks): Don't test `inhibit-point-motion-hooks`. (ergoemacs-command-loop--internal): Don't set `inhibit-point-motion-hooks`. * ergoemacs-advice.el: Require `ergoemacs-command-loop`. (ergoemacs--temporary-disable): Declare var as dynamic. --- ergoemacs-advice.el | 4 +- ergoemacs-command-loop.el | 453 +++++++++++++++++++++++----------------------- ergoemacs-cua.el | 19 +- ergoemacs-debug.el | 6 +- ergoemacs-functions.el | 102 +++++------ ergoemacs-layouts.el | 17 +- ergoemacs-macros.el | 105 +---------- ergoemacs-map.el | 66 +++---- ergoemacs-mapkeymap.el | 6 +- ergoemacs-mode.el | 18 +- ergoemacs-test.el | 129 +++++++------ ergoemacs-theme-engine.el | 9 +- ergoemacs-themes.el | 22 +-- ergoemacs-translate.el | 30 +-- 14 files changed, 440 insertions(+), 546 deletions(-) diff --git a/ergoemacs-advice.el b/ergoemacs-advice.el index de7756f9f8..450a60d6db 100644 --- a/ergoemacs-advice.el +++ b/ergoemacs-advice.el @@ -1,6 +1,6 @@ ;;; ergoemacs-advice.el --- Ergoemacs advices -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Filename: ergoemacs-advice.el ;; Description: @@ -35,6 +35,7 @@ (require 'mouse) (require 'nadvice) +(require 'ergoemacs-command-loop) (defvar ergoemacs-mode) (defvar ergoemacs-keymap) @@ -94,6 +95,7 @@ TYPE is the type of translation installed." (when (memq 'down (event-modifiers last-command-event)) current-prefix-arg))))) +(defvar ergoemacs--temporary-disable) (defun ergoemacs-advice-undefined (orig-fun) "Allow `ergoemacs-mode' to display keys, and intercept ending <apps> keys." (if (and ergoemacs-mode (not ergoemacs--temporary-disable)) diff --git a/ergoemacs-command-loop.el b/ergoemacs-command-loop.el index 01f5cf54e7..0185d7dd6a 100644 --- a/ergoemacs-command-loop.el +++ b/ergoemacs-command-loop.el @@ -1,5 +1,5 @@ ;;; ergoemacs-command-loop.el --- Keyboard translation functions -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Filename: ergoemacs-command-loop.el ;; Description: @@ -170,7 +170,7 @@ ignore the post-command hooks.") (defun ergoemacs-command-loop--execute-modify-command-list (command) "Set variables in `ergoemacs-command-loop--execute-modify-command-list' to COMMAND." - (ergoemacs-save-buffer-state + (with-silent-modifications (dolist (var ergoemacs-command-loop--execute-modify-command-list) (set var command)))) @@ -259,7 +259,7 @@ ignore the post-command hooks.") "Show modal translation. Returns the mode-line text." (let (tmp color text) - (ergoemacs-save-buffer-state + (with-silent-modifications (cond ((setq tmp (ergoemacs :modal-p)) (setq color (ergoemacs-translation-struct-modal-color tmp)) @@ -346,7 +346,7 @@ with this function." (when (> 1 (length new-key)) (error "Will not set a key sequence to the Emacs key sequence")) (setf (nth 3 cur-input) new-key) - (and (ignore-errors (apply 'set-input-mode cur-input)) + (and (ignore-errors (apply #'set-input-mode cur-input)) (message "Redefined Emacs quit key to %s" (ergoemacs-key-description (or key [7]))) t))) @@ -394,9 +394,9 @@ This is called through `ergoemacs-command-loop'" (setq ergoemacs-command-loop--universal t ergoemacs-command-loop--exit :ignore-post-command-hook)))) -(defalias 'ergoemacs-read-key--universal-argument 'ergoemacs-command-loop--universal-argument) +(defalias 'ergoemacs-read-key--universal-argument #'ergoemacs-command-loop--universal-argument) -(defalias 'ergoemacs-universal-argument 'ergoemacs-command-loop--universal-argument) +(defalias 'ergoemacs-universal-argument #'ergoemacs-command-loop--universal-argument) (defun ergoemacs-command-loop--digit-argument (&optional type) "Ergoemacs digit argument. @@ -413,7 +413,7 @@ Ergoemacs-mode sets up: :ctl-to-alt :unchorded :normal." (setq current-prefix-arg digit)) (ergoemacs-command-loop nil type nil t)) -(defalias 'ergoemacs-digit-argument 'ergoemacs-command-loop--digit-argument) +(defalias 'ergoemacs-digit-argument #'ergoemacs-command-loop--digit-argument) (defun ergoemacs-command-loop--negative-argument (&optional type) "Ergoemacs negative argument. @@ -425,7 +425,7 @@ Ergoemacs-mode sets up: :ctl-to-alt :unchorded :normal." (setq current-prefix-arg '-) (ergoemacs-command-loop nil type nil t)) -(defalias 'ergoemacs-negative-argument 'ergoemacs-command-loop--negative-argument) +(defalias 'ergoemacs-negative-argument #'ergoemacs-command-loop--negative-argument) (dolist (arg '((next-key-is-alt (meta)) (next-key-is-meta (meta)) @@ -439,20 +439,21 @@ Ergoemacs-mode sets up: :ctl-to-alt :unchorded :normal." (eval (macroexpand-all ;FIXME: Why macroexpand-all? `(progn (defun ,(intern (concat "ergoemacs-command-loop--" (symbol-name (nth 0 arg)))) () - ,(format "Ergoemacs function to allow %s to be the emacs modifiers" (nth 1 arg)) + ,(format "Ergoemacs function to allow %s to be the Emacs modifiers" (nth 1 arg)) (interactive) (message "Dummy Function for %s" (ergoemacs :modifier-desc ,(nth 1 arg)))) (defalias ',(intern (concat "ergoemacs-read-key-" (symbol-name (nth 0 arg)))) ',(intern (concat "ergoemacs-command-loop--" (symbol-name (nth 0 arg))))) (puthash ',(intern (concat "ergoemacs-command-loop--" (symbol-name (nth 0 arg)))) '(,(nth 1 arg) nil) ergoemacs-command-loop--next-key-hash) (puthash ',(intern (concat "ergoemacs-read-key-" (symbol-name (nth 0 arg)))) '(,(nth 1 arg) nil) ergoemacs-command-loop--next-key-hash) (defun ,(intern (concat "ergoemacs-command-loop--force-" (symbol-name (nth 0 arg)))) () - ,(format "Ergoemacs function to allow %s to be the emacs modifiers" (nth 1 arg)) + ,(format "Ergoemacs function to allow %s to be the Emacs modifiers" (nth 1 arg)) (interactive) (message "Dummy Function for %s" (ergoemacs :modifier-desc ,(nth 1 arg)))) (defalias ',(intern (concat "ergoemacs-read-key-force-" (symbol-name (nth 0 arg)))) ',(intern (concat "ergoemacs-command-loop--force-" (symbol-name (nth 0 arg))))) (puthash ',(intern (concat "ergoemacs-command-loop--force-" (symbol-name (nth 0 arg)))) '(,(nth 1 arg) :force) ergoemacs-command-loop--next-key-hash) (puthash ',(intern (concat "ergoemacs-read-key-force-" (symbol-name (nth 0 arg)))) '(,(nth 1 arg) :force) ergoemacs-command-loop--next-key-hash) - t)))) + t)) + t)) (defvar ergoemacs-last-command-event nil "`ergoemacs-mode' command loop last read command.") @@ -474,7 +475,7 @@ Uses the `ergoemacs-command-loop--history' variable/function." ;; Nothing to undo, exit the command loop. (setq ergoemacs-command-loop--exit t))) -(defalias 'ergoemacs-read-key-undo-last 'ergoemacs-command-loop--undo-last) +(defalias 'ergoemacs-read-key-undo-last #'ergoemacs-command-loop--undo-last) (defun ergoemacs-command-loop--force-undo-last () "Function to undo the last key-press. @@ -482,10 +483,10 @@ Uses the `ergoemacs-command-loop--history' variable/function." Unlike `ergoemacs-command-loop--undo-last', this ignores any bindings like \\[backward-kill-sentence] This is actually a dummy function. The actual work is done in `ergoemacs-command-loop'" (interactive) - (call-interactively 'ergoemacs-command-loop--undo-last)) + (call-interactively #'ergoemacs-command-loop--undo-last)) (put 'ergoemacs-command-loop--force-undo-last :ergoemacs-local :force) -(defalias 'ergoemacs-read-key-force-undo-last 'ergoemacs-command-loop--force-undo-last) +(defalias 'ergoemacs-read-key-force-undo-last #'ergoemacs-command-loop--force-undo-last) (put 'ergoemacs-read-key-force-undo-last :ergoemacs-local :force) (defun ergoemacs-command-loop--swap-translation () @@ -499,7 +500,7 @@ Uses the `ergoemacs-command-loop-swap-translation' variable." (nth 1 next-swap) :normal)))) -(defalias 'ergoemacs-read-key-swap 'ergoemacs-command-loop--swap-translation) +(defalias 'ergoemacs-read-key-swap #'ergoemacs-command-loop--swap-translation) (defun ergoemacs-command-loop--help () "Show help for the current sequence KEY." @@ -534,7 +535,7 @@ Uses the `ergoemacs-command-loop-swap-translation' variable." (describe-buffer-bindings cb key))) (setq ergoemacs-command-loop--exit t)))))) -(defalias 'ergoemacs-read-key-help 'ergoemacs-command-loop--help) +(defalias 'ergoemacs-read-key-help #'ergoemacs-command-loop--help) ;; Command Loop @@ -725,18 +726,18 @@ inconjunction with `input-method-function' to translate keys if (list (ergoemacs-translate--event-basic-type event)))))) (vector event))) (test-ret (lookup-key keymap current-test-key)) - (timeout-key (key-binding (vconcat current-test-key [ergoemacs-timeout]))) + ;; (timeout-key (key-binding (vconcat current-test-key [ergoemacs-timeout]))) next-key) (while (and current-test-key (ergoemacs-keymapp test-ret)) ;; The translation needs more keys... - (setq next-key (ergoemacs-command-loop--history nil ergoemacs-command-loop--decode-event-delay current-key)) + (setq next-key (ergoemacs-command-loop--history nil ergoemacs-command-loop--decode-event-delay current-key)) (when next-key ;; Since a key was read, save it to be read later. (push last-command-event new-ergoemacs-input)) (if next-key (setq current-test-key (ergoemacs :combine current-test-key next-key) - timeout-key (key-binding (vconcat current-test-key [ergoemacs-timeout])) + ;; timeout-key (key-binding (vconcat current-test-key [ergoemacs-timeout])) test-ret (lookup-key keymap current-test-key)) (setq current-test-key nil))) ;; Change strings to emacs keys. @@ -814,7 +815,7 @@ return nil." (setq binding (key-binding (ergoemacs :combine current-key input) t)))) input)) -(defun ergoemacs-command-loop--key-msg (blink-on universal text current-key unchorded trans keys) +(defun ergoemacs-command-loop--key-msg (blink-on universal text current-key unchorded _trans keys) "Key message. BLINK-ON is the flag for if the blink is on @@ -1224,7 +1225,7 @@ appropriate value based on the COMMAND." (not ergoemacs-command-loop--minibuffer-unsupported-p)) (when (or (and command (symbolp command) (string-match-p "^\\(calc\\|math\\)" (symbol-name command))) (and (stringp command) (string-match-p "^[^:]*:\\(calc\\|math\\)" command))) - (ergoemacs-save-buffer-state + (with-silent-modifications (set (make-local-variable 'ergoemacs-command-loop--minibuffer-unsupported-p) t))) (ergoemacs-command-loop--minibuffer-supported-p))) @@ -1288,9 +1289,9 @@ to start with "Record the last point.") (defun ergoemacs-command-loop--point-motion-hooks () - "Emlulate Emacs' command-loop portion of the point-motion hooks. + "Emulate Emacs' command-loop portion of the point-motion hooks. The properties `point-entered' and `point-left' are handled by C internals." - (unless (or disable-point-adjustment global-disable-point-adjustment inhibit-point-motion-hooks) + (unless (or disable-point-adjustment global-disable-point-adjustment) ;; Only the adjustment of the point in fishy areas is done in the ;; command loop. (let* ((props '(intangible composition display invisible)) @@ -1309,7 +1310,7 @@ The properties `point-entered' and `point-left' are handled by C internals." (setq last-point cur-point cur-point (point))))) (setq disable-point-adjustment nil) - (ergoemacs-save-buffer-state + (with-silent-modifications (set (make-local-variable 'ergoemacs-command-loop--point-motion-last-point) (point)))) (defun ergoemacs-command-loop--sync-point () @@ -1677,14 +1678,12 @@ instead of `format'." ((and (eq string :start) ergoemacs-mode-started-p)) ((and (eq string :start) (not ergoemacs-mode-started-p)) (setq ergoemacs-message-level :max) - (unwind-protect - (apply #'ergoemacs-command-loop--spinner-display args)) + (apply #'ergoemacs-command-loop--spinner-display args) (setq ergoemacs-message-level :start)) ((and (eq string :new) (memq ergoemacs-message-level '(:new))) (setq ergoemacs-command-loop--spinner-display :new) - (unwind-protect - (apply #'ergoemacs-command-loop--spinner-display args)) + (apply #'ergoemacs-command-loop--spinner-display args) (setq ergoemacs-command-loop--spinner-display :max))) (when (eq ergoemacs-message-level ergoemacs-command-loop--spinner-display) (let* ((string (or (and (listp string) @@ -1733,10 +1732,9 @@ They don't exactly behave like their Emacs equivalents." "Timer to startup `ergoemacs-mode' command loop.") (defun ergoemacs-command-loop--timer () "Start `ergoemacs-command-loop--internal' if not currently running." - (unwind-protect - (unless (and (ergoemacs-command-loop-full-p) - (ergoemacs-command-loop-p)) - (ergoemacs-command-loop--internal)))) + (unless (and (ergoemacs-command-loop-full-p) + (ergoemacs-command-loop-p)) + (ergoemacs-command-loop--internal))) (defun ergoemacs-command-loop--install-timer () "Install the `ergoemacs-command-loop--timer'." @@ -1824,166 +1822,160 @@ Emacs versions)." (local-keymap (ergoemacs-translate--keymap translation)) modal-p tmp command) - (unwind-protect - (progn - ;; Set these to nil when entering the command loop; - ;; - ;; For some reason `inhibit-point-motion-hooks' on emacs - ;; 25.1 is t when the command loop is entered. - ;; - ;; To allow the point motion hooks to work as - ;; advertised, set these on starting the command loop. - (setq inhibit-point-motion-hooks nil - disable-point-adjustment nil - global-disable-point-adjustment nil) - ;; Setup initial unread command events, first type and history - (setq tmp (ergoemacs-command-loop--listify-key-sequence key initial-key-type) - unread-command-events (or (and unread-command-events tmp (append tmp unread-command-events)) tmp) - ergoemacs-command-loop--first-type first-type - ergoemacs-command-loop--history initial-history - ergoemacs-command-loop-start nil) - (while continue-read - (setq ergoemacs-last-command-was-ergoemacs-ignore-p nil) - (unless (eq ergoemacs-command-loop-type :read-key-sequence) - (setq inhibit-quit t)) - (while continue-read - (setq ergoemacs-last-command-was-ergoemacs-ignore-p nil) - ;; Read key - (setq ergoemacs-command-loop--single-command-keys current-key - ergoemacs-command-loop--current-type type - ergoemacs-command-loop--universal universal - raw-key (ergoemacs-command-loop--read-key - current-key - (or (and unread-command-events :normal) type) - (and (not unread-command-events) universal)) - ergoemacs-command-loop--single-command-keys nil - universal-argument-num-events 0 - last-current-key current-key - current-key (nth 1 raw-key) - raw-key (nth 0 raw-key) - continue-read nil) - (when (setq modal-p (ergoemacs :modal-p)) - (setq local-keymap (ergoemacs-translation-struct-keymap-modal modal-p))) - (cond - ;; Handle quit commands - ((and last-current-key - (or (lookup-key ergoemacs-map--quit-map raw-key) - (and (equal raw-key [27]) - (lookup-key ergoemacs-map--quit-map [escape])))) - (ergoemacs-command-loop--message - "Key sequence %s aborted by %s" - (ergoemacs-key-description last-current-key) - (ergoemacs-key-description raw-key)) - (setq quit-flag t - ergoemacs-this-command-keys-shift-translated nil)) - ;; Handle local commands. - ((and (or modal-p - (not (equal current-key raw-key))) - (setq command (lookup-key local-keymap raw-key)) - (not (ergoemacs-keymapp command)) ;; Ignore locally - ;; Already handled by `ergoemacs-command-loop--read-key' - (not (ergoemacs-gethash command ergoemacs-command-loop--next-key-hash)) - ;; If a command has :ergoemacs-local property of :force, don't - ;; worry about looking up a key, just run the function. - (or modal-p - (and (symbolp command) (eq (get command :ergoemacs-local) :force)) - (not (key-binding current-key t)))) - (pop ergoemacs-command-loop--history) ;; Don't recored local events - (setq ergoemacs-command-loop--single-command-keys last-current-key - universal-argument-num-events 0 - ergoemacs-command-loop--current-type type - ergoemacs-command-loop--universal universal - ergoemacs-command-loop--exit nil) + ;; Set these to nil when entering the command loop; + ;; + ;; To allow the point motion hooks to work as + ;; advertised, set these on starting the command loop. + (setq disable-point-adjustment nil + global-disable-point-adjustment nil) + ;; Setup initial unread command events, first type and history + (setq tmp (ergoemacs-command-loop--listify-key-sequence key initial-key-type) + unread-command-events (or (and unread-command-events tmp (append tmp unread-command-events)) tmp) + ergoemacs-command-loop--first-type first-type + ergoemacs-command-loop--history initial-history + ergoemacs-command-loop-start nil) + (while continue-read + (setq ergoemacs-last-command-was-ergoemacs-ignore-p nil) + (unless (eq ergoemacs-command-loop-type :read-key-sequence) + (setq inhibit-quit t)) + (while continue-read + (setq ergoemacs-last-command-was-ergoemacs-ignore-p nil) + ;; Read key + (setq ergoemacs-command-loop--single-command-keys current-key + ergoemacs-command-loop--current-type type + ergoemacs-command-loop--universal universal + raw-key (ergoemacs-command-loop--read-key + current-key + (or (and unread-command-events :normal) type) + (and (not unread-command-events) universal)) + ergoemacs-command-loop--single-command-keys nil + universal-argument-num-events 0 + last-current-key current-key + current-key (nth 1 raw-key) + raw-key (nth 0 raw-key) + continue-read nil) + (when (setq modal-p (ergoemacs :modal-p)) + (setq local-keymap (ergoemacs-translation-struct-keymap-modal modal-p))) + (cond + ;; Handle quit commands + ((and last-current-key + (or (lookup-key ergoemacs-map--quit-map raw-key) + (and (equal raw-key [27]) + (lookup-key ergoemacs-map--quit-map [escape])))) + (ergoemacs-command-loop--message + "Key sequence %s aborted by %s" + (ergoemacs-key-description last-current-key) + (ergoemacs-key-description raw-key)) + (setq quit-flag t + ergoemacs-this-command-keys-shift-translated nil)) + ;; Handle local commands. + ((and (or modal-p + (not (equal current-key raw-key))) + (setq command (lookup-key local-keymap raw-key)) + (not (ergoemacs-keymapp command)) ;; Ignore locally + ;; Already handled by `ergoemacs-command-loop--read-key' + (not (ergoemacs-gethash command ergoemacs-command-loop--next-key-hash)) + ;; If a command has :ergoemacs-local property of :force, don't + ;; worry about looking up a key, just run the function. + (or modal-p + (and (symbolp command) (eq (get command :ergoemacs-local) :force)) + (not (key-binding current-key t)))) + (pop ergoemacs-command-loop--history) ;; Don't recored local events + (setq ergoemacs-command-loop--single-command-keys last-current-key + universal-argument-num-events 0 + ergoemacs-command-loop--current-type type + ergoemacs-command-loop--universal universal + ergoemacs-command-loop--exit nil) - (unless (eq ergoemacs-command-loop-type :test) - (setq tmp this-command - this-command command) - (ergoemacs-command-loop--call-interactively this-command) - (setq command this-command - this-command tmp)) - ;; If the command changed anything, fix it here. - (unless (equal type ergoemacs-command-loop--current-type) - (setq type ergoemacs-command-loop--current-type - translation (ergoemacs-translate--get type) - local-keymap (ergoemacs-translate--keymap translation))) + (unless (eq ergoemacs-command-loop-type :test) + (setq tmp this-command + this-command command) + (ergoemacs-command-loop--call-interactively this-command) + (setq command this-command + this-command tmp)) + ;; If the command changed anything, fix it here. + (unless (equal type ergoemacs-command-loop--current-type) + (setq type ergoemacs-command-loop--current-type + translation (ergoemacs-translate--get type) + local-keymap (ergoemacs-translate--keymap translation))) - (setq current-key ergoemacs-command-loop--single-command-keys - universal ergoemacs-command-loop--universal - ergoemacs-command-loop--single-command-keys nil - continue-read (not ergoemacs-command-loop--exit))) - ;; Handle any keys that are bound in some translatable way. - ((setq command (ergoemacs-command-loop--key-lookup current-key)) - ;; Setup external indicators of how the loop currently behaves. - (setq ergoemacs-command-loop--single-command-keys current-key - universal-argument-num-events 0 - ergoemacs-command-loop--current-type type - ergoemacs-command-loop--universal nil - ergoemacs-command-loop--exit t) - (if (setq continue-read (and (not (and (consp (aref current-key 0)) - (memq (event-basic-type (car (aref current-key 0))) - '(mouse-1 mouse-2 mouse-3 mouse-4 mouse-5 mouse-6 mouse-7 mouse-8 mouse-9)))) - (ergoemacs-keymapp command))) - (setq universal nil) - (unless (memq ergoemacs-command-loop-type '(:test :read-key-sequence)) - (with-local-quit - (ergoemacs-command-loop--execute command))) + (setq current-key ergoemacs-command-loop--single-command-keys + universal ergoemacs-command-loop--universal + ergoemacs-command-loop--single-command-keys nil + continue-read (not ergoemacs-command-loop--exit))) + ;; Handle any keys that are bound in some translatable way. + ((setq command (ergoemacs-command-loop--key-lookup current-key)) + ;; Setup external indicators of how the loop currently behaves. + (setq ergoemacs-command-loop--single-command-keys current-key + universal-argument-num-events 0 + ergoemacs-command-loop--current-type type + ergoemacs-command-loop--universal nil + ergoemacs-command-loop--exit t) + (if (setq continue-read (and (not (and (consp (aref current-key 0)) + (memq (event-basic-type (car (aref current-key 0))) + '(mouse-1 mouse-2 mouse-3 mouse-4 mouse-5 mouse-6 mouse-7 mouse-8 mouse-9)))) + (ergoemacs-keymapp command))) + (setq universal nil) + (unless (memq ergoemacs-command-loop-type '(:test :read-key-sequence)) + (with-local-quit + (ergoemacs-command-loop--execute command))) - (when quit-flag - (ergoemacs-command-loop--message "Quit!")) + (when quit-flag + (ergoemacs-command-loop--message "Quit!")) - ;; Change any information (if needed) - (unless (equal type ergoemacs-command-loop--current-type) - (setq type ergoemacs-command-loop--current-type - translation (ergoemacs-translate--get type) - local-keymap (ergoemacs-translate--keymap translation))) - - (when (eq ergoemacs-command-loop-type :read-key-sequence) - (setq ergoemacs-command-loop--exit t - continue-read nil - command current-key)) + ;; Change any information (if needed) + (unless (equal type ergoemacs-command-loop--current-type) + (setq type ergoemacs-command-loop--current-type + translation (ergoemacs-translate--get type) + local-keymap (ergoemacs-translate--keymap translation))) + + (when (eq ergoemacs-command-loop-type :read-key-sequence) + (setq ergoemacs-command-loop--exit t + continue-read nil + command current-key)) - (setq current-key ergoemacs-command-loop--single-command-keys - universal ergoemacs-command-loop--universal - ergoemacs-command-loop--single-command-keys nil - continue-read (not ergoemacs-command-loop--exit) - current-prefix-arg (if ergoemacs-command-loop--universal current-prefix-arg prefix-arg)) + (setq current-key ergoemacs-command-loop--single-command-keys + universal ergoemacs-command-loop--universal + ergoemacs-command-loop--single-command-keys nil + continue-read (not ergoemacs-command-loop--exit) + current-prefix-arg (if ergoemacs-command-loop--universal current-prefix-arg prefix-arg)) - (when (and (not continue-read) - (eq ergoemacs-command-loop--exit :ignore-post-command-hook)) - (setq continue-read t))) + (when (and (not continue-read) + (eq ergoemacs-command-loop--exit :ignore-post-command-hook)) + (setq continue-read t))) - (when (or (not ergoemacs-command-loop--exit) - (and (not continue-read) (setq continue-read unread-command-events))) - (ergoemacs-command-loop--internal-end-command))) - (quit-flag - (ergoemacs-command-loop--message "Quit!") - (setq quit-flag nil - type :normal - first-type :normal - raw-key nil - current-key nil - translation (ergoemacs-translate--get type) - local-keymap (ergoemacs-translate--keymap translation) - ergoemacs-command-loop--first-type first-type - ergoemacs-command-loop--history nil)) - ((consp (aref current-key 0))) ;; don't complain about mouse keys - (t ;; Command not found exit. - (ergoemacs-command-loop--message "Key %s doesn't do anything." (ergoemacs-key-description current-key))))) - (unless quit-flag - (ergoemacs-command-loop--internal-end-command)) - (setq quit-flag nil - type :normal - continue-read (or unread-command-events (and from-start-p (ergoemacs-command-loop-full-p))) - first-type :normal - raw-key nil - current-key nil - translation (ergoemacs-translate--get type) - local-keymap (ergoemacs-translate--keymap translation) - ergoemacs-command-loop--first-type first-type - ergoemacs-command-loop--history nil) - (when (or (not ergoemacs-mode) (eq :read-key-sequence ergoemacs-command-loop-type)) - (setq continue-read nil))) - (setq inhibit-quit nil))) + (when (or (not ergoemacs-command-loop--exit) + (and (not continue-read) (setq continue-read unread-command-events))) + (ergoemacs-command-loop--internal-end-command))) + (quit-flag + (ergoemacs-command-loop--message "Quit!") + (setq quit-flag nil + type :normal + first-type :normal + raw-key nil + current-key nil + translation (ergoemacs-translate--get type) + local-keymap (ergoemacs-translate--keymap translation) + ergoemacs-command-loop--first-type first-type + ergoemacs-command-loop--history nil)) + ((consp (aref current-key 0))) ;; don't complain about mouse keys + (t ;; Command not found exit. + (ergoemacs-command-loop--message "Key %s doesn't do anything." (ergoemacs-key-description current-key))))) + (unless quit-flag + (ergoemacs-command-loop--internal-end-command)) + (setq quit-flag nil + type :normal + continue-read (or unread-command-events (and from-start-p (ergoemacs-command-loop-full-p))) + first-type :normal + raw-key nil + current-key nil + translation (ergoemacs-translate--get type) + local-keymap (ergoemacs-translate--keymap translation) + ergoemacs-command-loop--first-type first-type + ergoemacs-command-loop--history nil) + (when (or (not ergoemacs-mode) (eq :read-key-sequence ergoemacs-command-loop-type)) + (setq continue-read nil))) + (setq inhibit-quit nil) command)))) (defcustom ergoemacs-message-in-mode-line t @@ -2270,62 +2262,61 @@ For instance in QWERTY M-> is shift translated to M-." ;; (3) execute command (defun ergoemacs-command-loop--execute (command &optional keys) "Execute COMMAND pretending that KEYS were pressed." - (unwind-protect - (let ((keys (or keys ergoemacs-command-loop--single-command-keys))) - ;; (ergoemacs-command-loop--spinner) + (let ((keys (or keys ergoemacs-command-loop--single-command-keys))) + ;; (ergoemacs-command-loop--spinner) + (cond + ((or (stringp command) (vectorp command)) + ;; If the command is a keyboard macro (string/vector) then execute + ;; it by adding it to `unread-command-events' + (let ((tmp (prefix-numeric-value current-prefix-arg))) (cond - ((or (stringp command) (vectorp command)) - ;; If the command is a keyboard macro (string/vector) then execute - ;; it by adding it to `unread-command-events' - (let ((tmp (prefix-numeric-value current-prefix-arg))) - (cond - ((<= tmp 0) ;; Unsure what to do here. - (ergoemacs-command-loop--message "The %s keyboard macro was not run %s times" (ergoemacs-key-description (vconcat command)) tmp)) - (t - (dotimes (_i tmp unread-command-events) - (setq unread-command-events - (append (listify-key-sequence command) - unread-command-events)))))) - (setq ergoemacs-command-loop--single-command-keys nil)) + ((<= tmp 0) ;; Unsure what to do here. + (ergoemacs-command-loop--message "The %s keyboard macro was not run %s times" (ergoemacs-key-description (vconcat command)) tmp)) (t - ;; This should be a regular command. + (dotimes (_i tmp unread-command-events) + (setq unread-command-events + (append (listify-key-sequence command) + unread-command-events)))))) + (setq ergoemacs-command-loop--single-command-keys nil)) + (t + ;; This should be a regular command. - ;; Remove counting of `this-command' in `keyfreq-mode' - ;; Shouldn't be needed any more... - ;; (ergoemacs-command-loop--execute-rm-keyfreq this-command) + ;; Remove counting of `this-command' in `keyfreq-mode' + ;; Shouldn't be needed any more... + ;; (ergoemacs-command-loop--execute-rm-keyfreq this-command) - ;; This command execute should modify the following variables: - ;; - `last-repeatable-command' - ;; - `this-command' - ;; - `this-original-command' + ;; This command execute should modify the following variables: + ;; - `last-repeatable-command' + ;; - `this-command' + ;; - `this-original-command' - ;; In addition, other minor modes may store the command, so these - ;; should be modified as well. + ;; In addition, other minor modes may store the command, so these + ;; should be modified as well. - ;; These are stored in `ergoemacs-command-loop--execute-modify-command-list' + ;; These are stored in `ergoemacs-command-loop--execute-modify-command-list' - (ergoemacs-command-loop--execute-modify-command-list command) + (ergoemacs-command-loop--execute-modify-command-list command) - ;; Handle Shift Selection - (ergoemacs-command-loop--execute-handle-shift-selection this-command) - (when keys - (setq ergoemacs-command-loop--single-command-keys keys) + ;; Handle Shift Selection + (ergoemacs-command-loop--execute-handle-shift-selection this-command) + (when keys + (setq ergoemacs-command-loop--single-command-keys keys) - ;; Modify the output for these functions when `keys' is not nil. + ;; Modify the output for these functions when `keys' is not nil. - ;; Assume this is a nonmenu event if it isn't a mouse event - (unless (consp last-command-event) - (setq last-nonmenu-event last-command-event))) - (unwind-protect - (progn - (setq ergoemacs-command-loop--running-pre-command-hook-p t) - (run-hooks 'pre-command-hook)) - (setq ergoemacs-command-loop--running-pre-command-hook-p nil)) - (unwind-protect - (ergoemacs-command-loop--call-interactively this-command t) - (setq ergoemacs-command-loop--single-command-keys nil))))) - ;; (ergoemacs-command-loop--spinner-end) - )) + ;; Assume this is a nonmenu event if it isn't a mouse event + (unless (consp last-command-event) + (setq last-nonmenu-event last-command-event))) + (unwind-protect + (progn + (setq ergoemacs-command-loop--running-pre-command-hook-p t) + (run-hooks 'pre-command-hook)) + (setq ergoemacs-command-loop--running-pre-command-hook-p nil)) + (unwind-protect + (ergoemacs-command-loop--call-interactively this-command t) + (setq ergoemacs-command-loop--single-command-keys nil))))) + ;; (ergoemacs-command-loop--spinner-end) + ) (defun ergoemacs-command-loop--shift-timeout () "This is the shift-timeout function for a key." (interactive) diff --git a/ergoemacs-cua.el b/ergoemacs-cua.el index f20d9d632c..423e3358f2 100644 --- a/ergoemacs-cua.el +++ b/ergoemacs-cua.el @@ -1,6 +1,6 @@ ;;; ergoemacs-cua.el --- Keyboard keybinding translation -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Filename: ergoemacs-cua.el ;; Description: @@ -61,21 +61,22 @@ (defvar ergoemacs--prefix-override-keymap (let ((map (make-sparse-keymap))) - (define-key map [(control x)] 'ergoemacs--prefix-override-handler) - (define-key map [(control c)] 'ergoemacs--prefix-override-handler) + (define-key map [(control x)] #'ergoemacs--prefix-override-handler) + (define-key map [(control c)] #'ergoemacs--prefix-override-handler) map) "Prefix override keymap.") (defvar ergoemacs--ena-prefix-repeat-keymap nil - "Variable that states that `ergoemacs-mode' is in the repeat phase, immediately after using the prefix key.") + "Non-nil if `ergoemacs-mode' is in the repeat phase, +I.e. immediately after using the prefix key.") (defvar ergoemacs--prefix-repeat-keymap (let ((map (make-sparse-keymap))) - (define-key map [(control x) (control x)] 'ergoemacs--prefix-repeat-handler) - (define-key map [(control c) (control c)] 'ergoemacs--prefix-repeat-handler) + (define-key map [(control x) (control x)] #'ergoemacs--prefix-repeat-handler) + (define-key map [(control c) (control c)] #'ergoemacs--prefix-repeat-handler) (dolist (key '(up down left right home end next prior)) - (define-key map (vector '(control x) key) 'ergoemacs--prefix-cut-handler) - (define-key map (vector '(control c) key) 'ergoemacs--prefix-copy-handler))) + (define-key map (vector '(control x) key) #'ergoemacs--prefix-cut-handler) + (define-key map (vector '(control c) key) #'ergoemacs--prefix-copy-handler))) "Prefix repeat keymap.") @@ -109,7 +110,7 @@ enabled." This is also used to select the region keymaps.") (defvar ergoemacs--ena-prefix-override-keymap nil - "Variable that tels the `ergoemacs-mode' of the overide step is active. + "Non-nil if `ergoemacs-mode's override step is active. This override is enabled for active regions before the copy and paste are enabled.") diff --git a/ergoemacs-debug.el b/ergoemacs-debug.el index e2949d2627..e1e170a5cb 100644 --- a/ergoemacs-debug.el +++ b/ergoemacs-debug.el @@ -1,6 +1,6 @@ ;;; ergoemacs-debug.el --- Ergoemacs map interface -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Filename: ergoemacs-debug.el ;; Description: @@ -58,7 +58,7 @@ "Ergoemacs debugging heading." (ergoemacs-debug (concat "** " (condition-case err - (apply 'format arg) + (apply #'format arg) (error (format "Bad format string: %s (%s)" arg err))))) (ergoemacs-debug "Time Since Start ergoemacs-mode: %1f sec" (- (float-time) ergoemacs-debug-heading-start-time)) (ergoemacs-debug "Time Since Last Heading: %1f sec" (- (float-time) ergoemacs-debug-heading-last-time)) @@ -79,7 +79,7 @@ (format "%s\n%s" ergoemacs-debug (condition-case err - (apply 'format arg) + (apply #'format arg) (error (format "Bad Format String: %s (%s)" arg err))))))) (defun ergoemacs-debug-clear () diff --git a/ergoemacs-functions.el b/ergoemacs-functions.el index 3227fb9384..55048cdb17 100644 --- a/ergoemacs-functions.el +++ b/ergoemacs-functions.el @@ -1,6 +1,6 @@ ;;; ergoemacs-functions.el --- miscellaneous functions for ErgoEmacs -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Maintainer: Matthew L. Fidler ;; Authors: Xah Lee, Matthew Fidler, Drew Adams, Ting-Yu Lin, David @@ -162,11 +162,6 @@ KEY3 is the optional third key in the sequence." (interactive) (ergoemacs--send-emacs-key ?\M-g ?\M-g)) -(defun ergoemacs-delete-char () - "Ergoemacs replacement for `delete-char' using `ergoemacs--send-emacs-key'." - (interactive) - (ergoemacs--send-emacs-key ?\C-d)) - (defun ergoemacs-move-beginning-of-line () "Ergoemacs replacement for `move-beginning-of-line' using `ergoemacs--send-emacs-key'." (interactive) @@ -484,7 +479,7 @@ When TERMINAL is non-nil, run in a terminal instead of GUI." (kill-buffer buf))) (switch-to-buffer-other-window (get-buffer-create "*ergoemacs-clean*")) (let ((inhibit-read-only t)) - (ergoemacs-save-buffer-state + (with-silent-modifications (set (make-local-variable 'ergoemacs-terminal) terminal)) (setq default-directory (expand-file-name (file-name-directory (locate-library "ergoemacs-mode")))) (delete-region (point-min) (point-max)) @@ -502,7 +497,7 @@ When TERMINAL is non-nil, run in a terminal instead of GUI." (process (start-process-shell-command "ergoemacs-byte-compile" "*ergoemacs-clean*" (format "%s -L %s -Q --batch -f batch-byte-compile ergoemacs-*.el" emacs-exe default-directory)))) - (set-process-sentinel process 'ergoemacs-run-clean)) + (set-process-sentinel process #'ergoemacs-run-clean)) (ergoemacs-run-clean nil nil)))) (defvar ergoemacs-run-clean nil @@ -515,7 +510,7 @@ The PROCESS is the process where the clean environment is run." (inhibit-read-only t) (ergoemacs-load (or ergoemacs-run-clean " --load=\"ergoemacs-mode\" --load=\"ergoemacs-test\" --eval \"(progn (require 'elp) (setq debug-on-error t) (elp-instrument-package (symbol-name 'ergoemacs-)) (ergoemacs-mode 1) (run-with-idle-timer 0.1 nil 'elp-results))\"")) - cmd process rm-batch) + cmd process) (cond ((with-current-buffer (get-buffer-create "*ergoemacs-clean*") (not ergoemacs-terminal)) @@ -528,7 +523,7 @@ The PROCESS is the process where the clean environment is run." emacs-exe (expand-file-name (file-name-directory (locate-library "ergoemacs-mode"))) ergoemacs-load)) - (ergoemacs-save-buffer-state + (with-silent-modifications (set (make-local-variable 'ergoemacs-batch-file) (make-temp-file "ergoemacs-clean" nil ".bat"))) (with-temp-file ergoemacs-batch-file @@ -543,17 +538,11 @@ The PROCESS is the process where the clean environment is run." (goto-char (point-max)) (insert "Command\n" cmd "\n\n")) (with-current-buffer (get-buffer-create "*ergoemacs-clean*") - (unless (eq major-mode 'compilation-mode) + (unless (derived-mode-p 'compilation-mode) (compilation-mode))) - (if (not rm-batch) - (setq process (start-process-shell-command "ergoemacs-run-clean" - "*ergoemacs-clean*" - cmd)) - (setq process (start-process - "ergoemacs-run-clean" "*ergoemacs-clean*" - (executable-find "cmd") - (file-name-nondirectory ergoemacs-batch-file))) - (set-process-sentinel process 'ergoemacs-run-clean-rm-batch)))) + (start-process-shell-command "ergoemacs-run-clean" + "*ergoemacs-clean*" + cmd))) (defun ergoemacs-run-clean-rm-batch () "Remove temporary batch file." @@ -854,9 +843,9 @@ followed by the beginning of indentation (if (defcustom ergoemacs-use-beginning-or-end-of-line-only 'on-repeat "Allow `ergoemacs-beginning-of-line-or-what' and `ergoemacs-end-of-line-or-what' to only go to the beginning/end of a line." :type '(choice - (const t :tag "Only go to the beginning or end of a line") - (const nil :tag "Goto beginning/end of block whenever at beginning/end of line") - (const on-repeat :tag "Goto beginning/end of block when at beginining/end of line and have already pressed the key.")) + (const :tag "Only go to the beginning or end of a line" t) + (const :tag "Goto beginning/end of block whenever at beginning/end of line" nil) + (const :tag "Goto beginning/end of block when at beginining/end of line and have already pressed the key." on-repeat)) :group 'ergoemacs-mode) (defcustom ergoemacs-beginning-or-end-of-line-and-what 'block @@ -867,10 +856,10 @@ When 'page use `scroll-down-command' or `scroll-up-command' When 'block use `ergoemacs-backward-block' or `ergoemacs-forward-block' When 'nil don't use a repeatable command." :type '(choice - (const buffer :tag "Goto beginning/end of buffer") - (const page :tag "Page Up") - (const block :tag "Goto beginning/end of block") - (const nil :tag "Do nothing on repeat at beginning/end of line")) + (const :tag "Goto beginning/end of buffer" buffer) + (const :tag "Page Up" page) + (const :tag "Goto beginning/end of block" block) + (const :tag "Do nothing on repeat at beginning/end of line" nil)) :group 'ergoemacs-mode) (defcustom ergoemacs-beginning-or-end-of-line-prefix-scrolls-other-window t @@ -1039,7 +1028,8 @@ the prefix arguments of `beginning-of-buffer', (ignore-errors (setq this-command 'scroll-other-window-down) (scroll-other-window-down) - t)) nil + t)) + nil (if (and ergoemacs-beginning-or-end-of-line-and-what (or (not ergoemacs-use-beginning-or-end-of-line-only) (and (eq 'on-repeat ergoemacs-use-beginning-or-end-of-line-only) @@ -1049,7 +1039,7 @@ the prefix arguments of `beginning-of-buffer', (cond ((eq ergoemacs-beginning-or-end-of-line-and-what 'buffer) (let ((pt (point))) - (beginning-of-buffer) + (goto-char (point-min)) (when (= pt (point)) (call-interactively 'beginning-of-buffer))) (setq this-command 'beginning-of-buffer)) @@ -1068,7 +1058,7 @@ the prefix arguments of `beginning-of-buffer', (let ((line-move-visual nil)) (forward-line (- N 1)))) (let (pts tmp) - (push (point-at-bol) pts) + (push (line-beginning-position) pts) (save-excursion ;; (setq prefix-arg nil) (setq current-prefix-arg nil) @@ -1093,13 +1083,13 @@ the prefix arguments of `beginning-of-buffer', (when (not (eolp)) (forward-char 1)) (save-excursion - (while (re-search-backward (format "%s" comment-start-skip) (point-at-bol) t)) - (while (re-search-forward (format "\\=%s" comment-start-skip) (point-at-eol) t)) + (while (re-search-backward (format "%s" comment-start-skip) (line-beginning-position) t)) + (while (re-search-forward (format "\\=%s" comment-start-skip) (line-end-position) t)) (push (point) pts) - (when (re-search-backward (format "%s\\=" comment-start-skip) (point-at-bol) t) - (while (re-search-backward (format "%s\\=" comment-start-skip) (point-at-bol) t) - (skip-chars-backward " \t" (point-at-bol))) - (skip-chars-backward " \t" (point-at-bol)) + (when (re-search-backward (format "%s\\=" comment-start-skip) (line-beginning-position) t) + (while (re-search-backward (format "%s\\=" comment-start-skip) (line-beginning-position) t) + (skip-chars-backward " \t" (line-beginning-position))) + (skip-chars-backward " \t" (line-beginning-position)) (push (point) pts))))) (cond ((not pts) @@ -1108,7 +1098,7 @@ the prefix arguments of `beginning-of-buffer', (when (= pt (point)) (call-interactively 'move-beginning-of-line)))) (t - (setq pts (sort pts '<)) + (setq pts (sort pts #'<)) (dolist (x pts) (save-excursion (goto-char x) @@ -1183,7 +1173,8 @@ the prefix arguments of `end-of-buffer', (ignore-errors (setq this-command 'scroll-other-window) (scroll-other-window) - t)) nil + t)) + nil (if (and ergoemacs-beginning-or-end-of-line-and-what (or (not ergoemacs-use-beginning-or-end-of-line-only) (and (eq 'on-repeat ergoemacs-use-beginning-or-end-of-line-only) @@ -1240,13 +1231,13 @@ the prefix arguments of `end-of-buffer', (when ergoemacs-end-of-comment-line (save-excursion ;; See http://www.emacswiki.org/emacs/EndOfLineNoComments - (goto-char (point-at-bol)) - (when (re-search-forward (format "%s" comment-start-skip) (point-at-eol) t) + (goto-char (line-beginning-position)) + (when (re-search-forward (format "%s" comment-start-skip) (line-end-position) t) (goto-char (match-beginning 0))) - (skip-syntax-backward " " (point-at-bol)) + (skip-syntax-backward " " (line-beginning-position)) (push (point) pts))) (when pts - (setq pts (sort pts '<)) + (setq pts (sort pts #'<)) (dolist (x pts) (unless (<= x (point)) (push x tmp))) @@ -1332,7 +1323,7 @@ Subsequent calls expands the selection to larger semantic unit." (mark-sexp -1)))) ;;; TEXT TRANSFORMATION RELATED -(defun ergoemacs-kill-line-backward (&optional number) +(defun ergoemacs-kill-line-backward (&optional _number) "Kill text between the beginning of the line to the cursor position. If there's no text, delete the previous line ending." (interactive "p") @@ -1528,10 +1519,11 @@ Based on the value of `major-mode' and (defun ergoemacs-camelize-method (s &optional char) "Convert under_score string S to CamelCase string." - (mapconcat 'identity (ergoemacs-mapcar-head - #'downcase - '(lambda (word) (capitalize (downcase word))) - (split-string s (or char "_"))) "")) + (mapconcat #'identity (ergoemacs-mapcar-head + #'downcase + (lambda (word) (capitalize (downcase word))) + (split-string s (or char "_"))) + "")) (defun ergoemacs-camel-bounds (camel-case-chars) "Return the camel-case bounds. @@ -1781,7 +1773,7 @@ binding." (defcustom ergoemacs-maximum-number-of-file-to-open 5 "Maximum number of files to open. If less than or equal to zero, there is no limit." - :type 'integerp + :type 'integer :group 'ergoemacs-mode) (defun ergoemacs-open-in-external-app (&optional file) "Open the current file or dired marked files in external app. @@ -2184,7 +2176,7 @@ When in `browse-kill-ring-mode', cycle backward through the key ring. "Run `yank' or `yank-pop' if this command is repeated. This is `yank' if `ergoemacs-smart-paste' is nil. This is `yank-pop' if `ergoemacs-smart-paste' is t and last command is a yank. -This is `browse-kill-ring' if `ergoemacs-smart-paste' equals 'browse-kill-ring and last command is a yank. +This is `browse-kill-ring' if `ergoemacs-smart-paste' equals `browse-kill-ring' and last command is a yank. When in `browse-kill-ring-mode', cycle forward through the key ring. @@ -2341,9 +2333,11 @@ ARG is the prefix argument for either command." direction direction direction) (defun ergoemacs-camelize (s &optional char) "Convert under_score string S to CamelCase string." - (mapconcat 'identity (mapcar + (mapconcat #'identity (mapcar + ;; FIXME: Is this different from just `capitalize'? (lambda (word) (capitalize (downcase word))) - (split-string s (or char "_"))) "")) + (split-string s (or char "_"))) + "")) @@ -2545,17 +2539,17 @@ Sends shell prompt string to process, then turns on (require 'dirtrack) (cond ((string-match "cmd\\(proxy\\)?.exe" shell) - (ergoemacs-save-buffer-state + (with-silent-modifications (set (make-local-variable 'dirtrack-list) (list "^\\([a-zA-Z]:.*\\)>" 1))) (shell-dirtrack-mode -1) (dirtrack-mode 1)) ((string-match "powershell.exe" shell) - (ergoemacs-save-buffer-state + (with-silent-modifications (set (make-local-variable 'dirtrack-list) (list "^PS \\([a-zA-Z]:.*\\)>" 1))) (shell-dirtrack-mode -1) (dirtrack-mode 1)) (t ;; Assume basic abc@host:dir structure - (ergoemacs-save-buffer-state + (with-silent-modifications (set (make-local-variable 'dirtrack-list) (list "^\\(?:.*?@\\)?\\(?:.*?:\\)?\\(?:[^ ]* \\)? *\\(.*\\) *\\([$#]\\|\\]\\)" 1))) (shell-dirtrack-mode -1) (dirtrack-mode 1)))))) diff --git a/ergoemacs-layouts.el b/ergoemacs-layouts.el index c0f38120d7..7642c87c8b 100644 --- a/ergoemacs-layouts.el +++ b/ergoemacs-layouts.el @@ -1,6 +1,6 @@ -;;; ergoemacs-layouts.el --- keyboard layouts for ErgoEmacs -* lexical-binding: t -*- +;;; ergoemacs-layouts.el --- keyboard layouts for ErgoEmacs -*- lexical-binding: t -*- -;; Copyright (C) 2013-2021 Free Software Foundation, Inc. +;; Copyright (C) 2013-2023 Free Software Foundation, Inc. ;; Maintainer: Matthew L. Fidler ;; Keywords: convenience @@ -415,7 +415,7 @@ If LAYOUT is unspecified, use `ergoemacs-keyboard-layout'." ,@(mapcar (lambda(elt) `(const :tag ,elt :value ,elt)) - (sort (ergoemacs-layouts--list t) 'string<)))) + (sort (ergoemacs-layouts--list t) #'string<)))) (defun ergoemacs-layouts--custom-documentation (&optional lays ini) "Get a documentation list of all known layouts. @@ -424,7 +424,7 @@ LAYS is the layouts being processed. If INI is non-nil, create information about the autohotkey ini file." - (let ((lays (or lays (sort (ergoemacs-layouts--list t) 'string<)))) + (let ((lays (or lays (sort (ergoemacs-layouts--list t) #'string<)))) (mapconcat (lambda(lay) (let* ((variable (intern (concat "ergoemacs-layout-" lay))) @@ -543,8 +543,7 @@ Otherwise, `ergoemacs-mode' will try to adjust based on your layout." when BASE is non-nil, the regular expression shows the regular expression matching the base layout." - (let ((reg (regexp-opt (ergoemacs-layouts--list t) t)) - (f1 "[\"`']\\(%s\\)[\"`']") + (let ((f1 "[\"`']\\(%s\\)[\"`']") (f2 "Base Layout: \\(%s\\)")) (format (cond (base f2) @@ -578,14 +577,10 @@ LAYOUT can be either a symbol or string." (s (intern (concat "ergoemacs-layout-" layout))) (sv (and (boundp s) (symbol-value s))) (el-file (find-lisp-object-file-name s 'defvar)) - (alias (condition-case nil - (indirect-variable s) - (error s))) (doc (or (documentation-property s 'variable-documentation) (documentation-property s 'variable-documentation))) - pt png svg) (unless (featurep 'quail) (require 'quail)) @@ -653,7 +648,7 @@ LAYOUT can be either a symbol or string." ;; Return the text we displayed. (buffer-string)))))) -(defalias 'describe-ergoemacs-layout 'ergoemacs-layout-describe) +(defalias 'describe-ergoemacs-layout #'ergoemacs-layout-describe) (provide 'ergoemacs-layouts) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/ergoemacs-macros.el b/ergoemacs-macros.el index cae95e474a..a6c1883b29 100644 --- a/ergoemacs-macros.el +++ b/ergoemacs-macros.el @@ -1,6 +1,6 @@ ;;; ergoemacs-macros.el --- Macros for ergoemacs-mode -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Maintainer: Matthew L. Fidler ;; Keywords: convenience @@ -101,44 +101,8 @@ additional parsing routines defined by PARSE-FUNCTION." (list plist remaining)))) ;;;###autoload -(defmacro ergoemacs-save-buffer-state (&rest body) - "Eval BODY, -then restore the buffer state under the assumption that no significant -modification has been made in BODY. A change is considered -significant if it affects the buffer text in any way that isn't -completely restored again. Changes in text properties like `face' or -`syntax-table' are considered insignificant. This macro allows text -properties to be changed, even in a read-only buffer. - -This macro should be placed around all calculations which set -\"insignificant\" text properties in a buffer, even when the buffer is -known to be writeable. That way, these text properties remain set -even if the user undoes the command which set them. - -This macro should ALWAYS be placed around \"temporary\" internal buffer -changes \(like adding a newline to calculate a text-property then -deleting it again\), so that the user never sees them on his -`buffer-undo-list'. - -However, any user-visible changes to the buffer \(like auto-newlines\) -must not be within a `ergoemacs-save-buffer-state', since the user then -wouldn't be able to undo them. - -The return value is the value of the last form in BODY. - -This was stole/modified from `c-save-buffer-state'" - `(let* ((modified (buffer-modified-p)) (buffer-undo-list t) - (inhibit-read-only t) (inhibit-point-motion-hooks t) - before-change-functions after-change-functions - deactivate-mark - buffer-file-name buffer-file-truename ; Prevent primitives checking - ; for file modification - ) - (unwind-protect - (progn ,@body) - (and (not modified) - (buffer-modified-p) - (set-buffer-modified-p nil))))) +(define-obsolete-function-alias 'ergoemacs-save-buffer-state + #'with-silent-modifications "2023") (defvar ergoemacs--map-properties-list '( @@ -305,64 +269,13 @@ This also creates functions: - ergoemacs-translate--NAME-modal" (declare (doc-string 2) (indent 2)) - (let ((kb (make-symbol "kb"))) - (setq kb (ergoemacs-theme-component--parse-keys-and-body body-and-plist)) + (let ((kb (ergoemacs-theme-component--parse-keys-and-body body-and-plist))) - `(progn (puthash ,(intern (concat ":" (plist-get (nth 0 kb) ':name))) - (lambda() ,(plist-get (nth 0 kb) ':description) - (ergoemacs-translate--create :key ,(intern (concat ":" (plist-get (nth 0 kb) ':name))) - ,@(nth 0 kb))) ergoemacs-translation-hash)))) - -(defmacro ergoemacs-advice (function args &rest body-and-plist) - "Defines an `ergoemacs-mode' advice. - -The structure is (ergoemacs-advice function args tags body-and-plist) - -When the tag :type equals :replace, the advice replaces the function. - -When :type is :replace that replaces a function (like `define-key')" - (declare (doc-string 2) - (indent 2)) - (let ((kb (make-symbol "kb"))) - (setq kb (ergoemacs-theme-component--parse-keys-and-body `(nil nil ,@body-and-plist))) - (cond - ((eq (plist-get (nth 0 kb) :type) :around) - ;; FIXME: use `nadvice' for emacs 24.4+ - (macroexpand-all `(progn - (defadvice ,function (around ,(intern (format "ergoemacs-advice--%s" (symbol-name function))) ,args activate) - ,(plist-get (nth 0 kb) :description) - ,@(nth 1 kb))))) - ((eq (plist-get (nth 0 kb) :type) :after) - ;; FIXME: use `nadvice' for emacs 24.4+ - (macroexpand-all - `(progn - (defadvice ,function (after ,(intern (format "ergoemacs-advice--after-%s" (symbol-name function))) ,args activate) - ,(plist-get (nth 0 kb) :description) - ,@(nth 1 kb))))) - ((eq (plist-get (nth 0 kb) :type) :before) - ;; FIXME: use `nadvice' for emacs 24.4+ - (macroexpand-all `(progn - (defadvice ,function (before ,(intern (format "ergoemacs-advice--%s" (symbol-name function))) ,args activate) - ,(plist-get (nth 0 kb) :description) - ,@(nth 1 kb))))) - ((eq (plist-get (nth 0 kb) :type) :replace) - (macroexpand-all `(progn - (defalias ',(intern (format "ergoemacs-advice--real-%s" (symbol-name function))) - (symbol-function ',function) (concat ,(format "ARGS=%s\n\n" args) (documentation ',function) - ,(format "\n\n`ergoemacs-mode' preserved the real `%s' in this function." - (symbol-name function)))) - (defun ,(intern (format "ergoemacs-advice--%s--" function)) ,args - ,(format "%s\n\n%s\n\n`ergoemacs-mode' replacement function for `%s'.\nOriginal function is preserved in `ergoemacs-advice--real-%s'" - (documentation function) - (plist-get (nth 0 kb) :description) (symbol-name function) (symbol-name function)) - ,@(nth 1 kb)) - ;; Hack to make sure the documentation is in the function... - (defalias ',(intern (format "ergoemacs-advice--%s" function)) ',(intern (format "ergoemacs-advice--%s--" function)) - ,(format "ARGS=%s\n\n%s\n\n%s\n\n`ergoemacs-mode' replacement function for `%s'.\nOriginal function is preserved in `ergoemacs-advice--real-%s'" - args (documentation function) (plist-get (nth 0 kb) :description) (symbol-name function) (symbol-name function))) - ,(if (plist-get (nth 0 kb) :always) - `(push ',function ergoemacs-advice--permanent-replace-functions) - `(push ',function ergoemacs-advice--temp-replace-functions)))))))) + `(puthash ,(intern (concat ":" (plist-get (nth 0 kb) ':name))) + (lambda() ,(plist-get (nth 0 kb) ':description) + (ergoemacs-translate--create :key ,(intern (concat ":" (plist-get (nth 0 kb) ':name))) + ,@(nth 0 kb))) + ergoemacs-translation-hash))) (defmacro ergoemacs-save-key-state (keymap-symbol &rest body) diff --git a/ergoemacs-map.el b/ergoemacs-map.el index 3771b50d7a..bd44e2a62e 100644 --- a/ergoemacs-map.el +++ b/ergoemacs-map.el @@ -1,6 +1,6 @@ ;;; ergoemacs-map.el --- Ergoemacs map interface -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Filename: ergoemacs-map.el ;; Description: @@ -183,43 +183,43 @@ save the infromationin the `ergoemacs-map--alist' hash." (let ((old-breadcrumb ergoemacs-map--breadcrumb) breadcrumb-base type old-len) (if (and symbol (setq old-len (ergoemacs-gethash symbol ergoemacs-map--alist)) - (= (length alist) old-len)) alist + (= (length alist) old-len)) + alist (when symbol (puthash symbol (length alist) ergoemacs-map--alist) (setq breadcrumb-base (format "%s:%s" old-breadcrumb symbol))) (setq ergoemacs-map--alist-atom-symbol-reset-when-volatile symbol) (prog1 - (unwind-protect - (prog1 (mapcar - (lambda(elt) - (cond - ;; ((not (ergoemacs-sv (car elt))) - ;; ;; not enabled, ignore any changes to this map...? - ;; elt) - ((eq (car elt) 'ergoemacs-mode) elt) - ((and (not (setq type (ergoemacs (cdr elt) :installed-p))) ergoemacs-mode) - ;; Install `ergoemacs-mode' into the keymap - (ergoemacs-map--alist-atom (car elt) (cdr elt) breadcrumb-base)) - ((not type) - ;; Install `ergoemacs-mode' user protection into the - ;; keymap. - (ergoemacs-map--alist-atom (car elt) (cdr elt) breadcrumb-base t)) - ((eq :cond-map type) - ;; Don't change conditional maps. Change in alists...? - elt) - ((and ergoemacs-mode (eq :protected-p type)) - ;; Change protection into full ergoemacs-mode installation - (ergoemacs-map--alist-atom (car elt) (ergoemacs (cdr elt) :original) breadcrumb-base)) - ((eq :protected-p type) - ;; Already protected. - elt) - ((and ergoemacs-mode type) - ;; Already installed - elt) - ((and (not ergoemacs-mode) type) - (ergoemacs-map--alist-atom (car elt) (ergoemacs (cdr elt) :original-user) breadcrumb-base)))) - alist) - (setq ergoemacs-map--breadcrumb old-breadcrumb))) + (mapcar + (lambda(elt) + (cond + ;; ((not (ergoemacs-sv (car elt))) + ;; ;; not enabled, ignore any changes to this map...? + ;; elt) + ((eq (car elt) 'ergoemacs-mode) elt) + ((and (not (setq type (ergoemacs (cdr elt) :installed-p))) ergoemacs-mode) + ;; Install `ergoemacs-mode' into the keymap + (ergoemacs-map--alist-atom (car elt) (cdr elt) breadcrumb-base)) + ((not type) + ;; Install `ergoemacs-mode' user protection into the + ;; keymap. + (ergoemacs-map--alist-atom (car elt) (cdr elt) breadcrumb-base t)) + ((eq :cond-map type) + ;; Don't change conditional maps. Change in alists...? + elt) + ((and ergoemacs-mode (eq :protected-p type)) + ;; Change protection into full ergoemacs-mode installation + (ergoemacs-map--alist-atom (car elt) (ergoemacs (cdr elt) :original) breadcrumb-base)) + ((eq :protected-p type) + ;; Already protected. + elt) + ((and ergoemacs-mode type) + ;; Already installed + elt) + ((and (not ergoemacs-mode) type) + (ergoemacs-map--alist-atom (car elt) (ergoemacs (cdr elt) :original-user) breadcrumb-base)))) + alist) + (setq ergoemacs-map--breadcrumb old-breadcrumb) (setq ergoemacs-map--alist-atom-symbol-reset-when-volatile nil))))) (defvar ergoemacs-map--alists (make-hash-table)) diff --git a/ergoemacs-mapkeymap.el b/ergoemacs-mapkeymap.el index 6f8a509c06..7850a369b5 100644 --- a/ergoemacs-mapkeymap.el +++ b/ergoemacs-mapkeymap.el @@ -136,7 +136,7 @@ them to be masked when mapping over the keymap." (make-keymap)))) composed-list parent - calc-parent-p + ;; calc-parent-p prefix-map tmp) (when (not prefix) @@ -164,9 +164,9 @@ them to be masked when mapping over the keymap." (when function (funcall function key 'ergoemacs-prefix)) (ergoemacs-map-keymap--map-submap item function original key flat-keymap nil-keys) - (unless calc-parent-p + ;; (unless calc-parent-p (setq composed-list (ergoemacs :composed-list keymap) - parent (keymap-parent keymap))) + parent (keymap-parent keymap)) ;;) (if composed-list (dolist (map composed-list) (when (and (ergoemacs-keymapp map) diff --git a/ergoemacs-mode.el b/ergoemacs-mode.el index fa94c9ddc8..2c0eabcfb8 100644 --- a/ergoemacs-mode.el +++ b/ergoemacs-mode.el @@ -1,6 +1,6 @@ ;;; ergoemacs-mode.el --- Emacs mode based on common modern interface and ergonomics. -*- lexical-binding: t -*- -;; Copyright © 2007-2010, 2012-2021 Free Software Foundation, Inc. +;; Copyright © 2007-2023 Free Software Foundation, Inc. ;; Author: Xah Lee <x...@xahlee.org> ;; David Capello <davidcape...@gmail.com> @@ -305,10 +305,10 @@ Home page URL `http://ergoemacs.github.io/' The `execute-extended-command' is now \\[execute-extended-command]. " - nil :lighter " ErgoEmacs" :global t :group 'ergoemacs-mode + ;; FIXME: This var is only ever set: never used! (setq ergoemacs-mode--start-p t) (if ergoemacs-mode (progn @@ -335,7 +335,7 @@ The `execute-extended-command' is now \\[execute-extended-command]. ((string-equal ergoemacs-theme "reduction") (ergoemacs-setup-override-keymap)) (t (ergoemacs-setup-override-keymap))) - (setq ergoemacs-require--ini-p t + (setq ergoemacs-require--ini-p t ;FIXME: Unused? ergoemacs-send-keys-term ergoemacs-mode-send-emacs-keys) (message "Ergoemacs-mode turned ON (%s)." ergoemacs-keyboard-layout)) @@ -432,13 +432,12 @@ This is structured by valid keyboard layouts for basic ergoemacs functionality. For example, if you want M-t to transpose words instead of running completion, call - (ergoemacs-define-key ergoemacs-override-keymap (kbd \"M-t\") 'transpose-words) + (ergoemacs-define-key ergoemacs-override-keymap (kbd \"M-t\") #\\='transpose-words) -after initializing ergoemacs-mode. -") +after initializing ergoemacs-mode.") (defvar ergoemacs-mark-active-keymap (let ((map (make-sparse-keymap))) - (define-key map (kbd "TAB") 'indent-region) + (define-key map (kbd "TAB") #'indent-region) (define-key map [(shift control x)] 'ergoemacs--shift-control-x-prefix) (define-key map [(shift control c)] 'ergoemacs--shift-control-c-prefix) map) @@ -470,13 +469,14 @@ after initializing ergoemacs-mode. (ergoemacs-mode-regular . ,ergoemacs-override-keymap) (ergoemacs-mode-regular . ,ergoemacs-keymap) (ergoemacs-mode-send-emacs-keys . ,ergoemacs--send-emacs-keys-map))) - (add-hook 'emulation-mode-map-alists ergoemacs-override-alist) + (add-to-list 'emulation-mode-map-alists ergoemacs-override-alist) (advice-add 'undefined :around #'ergoemacs-advice-undefined) (advice-add 'read-key :around #'ergoemacs-read-key)) (defun ergoemacs-remove-override-keymap () "Remove `ergoemacs-mode' keymaps." - (remove-hook 'emulation-mode-map-alists 'ergoemacs-override-alist) + (setq emulation-mode-map-alists + (delq ergoemacs-override-alist emulation-mode-map-alists)) (advice-remove 'undefined #'ergoemacs-advice-undefined) (advice-remove 'read-key #'ergoemacs-read-key)) diff --git a/ergoemacs-test.el b/ergoemacs-test.el index 5d8591fd40..eb278af377 100644 --- a/ergoemacs-test.el +++ b/ergoemacs-test.el @@ -1,6 +1,6 @@ -;;; ergoemacs-test.el --- tests for ErgoEmacs issues +;;; ergoemacs-test.el --- tests for ErgoEmacs issues -*- lexical-binding: t; -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Maintainer: Matthew L. Fidler ;; Keywords: convenience @@ -28,6 +28,10 @@ ;;; Code: +(require 'ergoemacs-functions) +(require 'ergoemacs-command-loop) +(require 'ergoemacs-translate) + (eval-when-compile (require 'cl-lib) (require 'ergoemacs-macros)) @@ -135,8 +139,9 @@ sunt in culpa qui officia deserunt mollit anim id est laborum.") (defun ergoemacs-test () "Test ergoemacs issues." (interactive) - (let ((ret t) - (test)) + (let (;; (ret t) + ;; (test) + ) (elp-instrument-package "ergoemacs-") (ert "^ergoemacs-test-") (call-interactively 'elp-results))) @@ -174,16 +179,16 @@ not using cua or cutting line. I think kill-region is what is meant." (goto-char (point-max)) (call-interactively 'ergoemacs-beginning-of-line-or-what) (should (string= "Turn on ergoemacs-mode" - (buffer-substring (point) (point-at-eol)))) + (buffer-substring (point) (line-end-position)))) (call-interactively 'ergoemacs-beginning-of-line-or-what) (should (string= " ; Turn on ergoemacs-mode" - (buffer-substring (point) (point-at-eol)))) + (buffer-substring (point) (line-end-position)))) (call-interactively 'ergoemacs-beginning-of-line-or-what) (should (string= "(ergoemacs-mode 1)) ; Turn on ergoemacs-mode" - (buffer-substring (point) (point-at-eol)))) + (buffer-substring (point) (line-end-position)))) (call-interactively 'ergoemacs-beginning-of-line-or-what) (should (string= " (ergoemacs-mode 1)) ; Turn on ergoemacs-mode" - (buffer-substring (point) (point-at-eol))))))) + (buffer-substring (point) (line-end-position))))))) (ert-deftest ergoemacs-test-function-eol-or-what () @@ -198,9 +203,9 @@ not using cua or cutting line. I think kill-region is what is meant." (call-interactively 'ergoemacs-end-of-line-or-what) (should (string= " ; Turn on ergoemacs-mode" - (buffer-substring (point) (point-at-eol)))) + (buffer-substring (point) (line-end-position)))) (call-interactively 'ergoemacs-end-of-line-or-what) - (should (= (point) (point-at-eol)))))) + (should (= (point) (line-end-position)))))) (ert-deftest ergoemacs-test-function-unbind-commands-active () "Make sure the unbound keys work" @@ -243,7 +248,7 @@ See Issue #138." (w-file (expand-file-name "global-test" ergoemacs-dir)) (temp-file (make-temp-file "ergoemacs-test" nil ".el"))) (setq sk - (format "(%s '(lambda() (interactive) (with-temp-file \"%s\" (insert \"Ok\"))))" + (format "(%s (lambda() (interactive) (with-temp-file \"%s\" (insert \"Ok\"))))" (cond ((eq ergoemacs 'define-key) (format "define-key global-map (kbd \"%s\") " test-key)) @@ -346,16 +351,15 @@ See Issue #138." "Major mode for testing some issues with `ergoemacs-mode'. \\{ergoemacs-test-major-mode-map}") -(define-key ergoemacs-test-major-mode-map (kbd "C-s") 'search-forward) -(define-key ergoemacs-test-major-mode-map (kbd "<f6>") 'search-forward) -(define-key ergoemacs-test-major-mode-map (kbd "M-s a") 'isearch-forward) -(define-key ergoemacs-test-major-mode-map (kbd "M-s b") 'isearch-backward) +(define-key ergoemacs-test-major-mode-map (kbd "C-s") #'search-forward) +(define-key ergoemacs-test-major-mode-map (kbd "<f6>") #'search-forward) +(define-key ergoemacs-test-major-mode-map (kbd "M-s a") #'isearch-forward) +(define-key ergoemacs-test-major-mode-map (kbd "M-s b") #'isearch-backward) -(let ((ergoemacs-is-user-defined-map-change-p t)) +;; (let ((ergoemacs-is-user-defined-map-change-p t)) (add-hook 'ergoemacs-test-major-mode-hook - '(lambda() - (interactive) - (define-key ergoemacs-test-major-mode-map (kbd "C-w") 'ergoemacs-close-current-buffer)))) + (lambda() + (define-key ergoemacs-test-major-mode-map (kbd "C-w") #'ergoemacs-close-current-buffer))) ;; ) (ert-deftest ergoemacs-test-issue-349 () "Unbind <f6>" @@ -388,10 +392,12 @@ See Issue #138." (when (file-exists-p w-file) (delete-file w-file)))) +(defvar ergoemacs-use-function-remapping) + (ert-deftest ergoemacs-test-ignore-ctl-w () "Keep user-defined C-w in major-mode `ergoemacs-test-major-mode'. Part of addressing Issue #147." - (let (ret + (let (;; ret (ergoemacs-use-function-remapping t)) (with-temp-buffer (ergoemacs-test-major-mode) @@ -401,55 +407,48 @@ Part of addressing Issue #147." ;; The user-defined C-w should not affect kill-region remaps. (should (not (eq (key-binding [ergoemacs-remap kill-region]) 'ergoemacs-close-current-buffer)))))) + +(require 'dired) + +(defvar ergoemacs-test--dired-sort-map + (let ((map (make-sparse-keymap))) + (define-key map "s" + (lambda () "sort by Size" + (interactive) (dired-sort-other (concat dired-listing-switches "-AlS --si --time-style long-iso")))) + (define-key map "." + (lambda () "sort by eXtension" + (interactive) (dired-sort-other (concat dired-listing-switches "X")))) + (define-key map "t" + (lambda () "sort by Time" + (interactive) (dired-sort-other (concat dired-listing-switches "t")))) + (define-key map "n" + (lambda () "sort by Name" + (interactive) (dired-sort-other (concat dired-listing-switches "")))) + map)) + + +(defun ergoemacs-test--dired-hook () + (define-key dired-mode-map "s" ergoemacs-test--dired-sort-map) + ;; Use "|", not "r". + (define-key dired-mode-map "|" #'dired-sort-menu-toggle-reverse) + ) + (ert-deftest ergoemacs-test-dired-sort-files () "Test Issue #340" - (add-hook 'dired-mode-hook (lambda () - (interactive) - (make-local-variable 'dired-sort-map) - (setq dired-sort-map (make-sparse-keymap)) - (define-key dired-mode-map "s" dired-sort-map) - (define-key dired-sort-map "s" - '(lambda () "sort by Size" - (interactive) (dired-sort-other (concat dired-listing-switches "-AlS --si --time-style long-iso")))) - (define-key dired-sort-map "." - '(lambda () "sort by eXtension" - (interactive) (dired-sort-other (concat dired-listing-switches "X")))) - (define-key dired-sort-map "t" - '(lambda () "sort by Time" - (interactive) (dired-sort-other (concat dired-listing-switches "t")))) - (define-key dired-sort-map "n" - '(lambda () "sort by Name" - (interactive) (dired-sort-other (concat dired-listing-switches "")))) - ;; Use "|", not "r". - (define-key dired-mode-map "|" 'dired-sort-menu-toggle-reverse) - )) + (add-hook 'dired-mode-hook #'ergoemacs-test--dired-hook) (dired ergoemacs-dir) - (should (equal (key-binding (kbd "s s")) '(lambda () "sort by Size" (interactive) (dired-sort-other (concat dired-listing-switches "-AlS --si --time-style long-iso"))))) - (should (equal (key-binding (kbd "s .")) '(lambda () "sort by eXtension" (interactive) (dired-sort-other (concat dired-listing-switches "X"))))) - (should (equal (key-binding (kbd "s t")) '(lambda () "sort by Time" (interactive) (dired-sort-other (concat dired-listing-switches "t"))))) - (should (equal (key-binding (kbd "s n")) '(lambda () "sort by Name" (interactive) (dired-sort-other (concat dired-listing-switches ""))))) - (should (equal (key-binding (kbd "|")) 'dired-sort-menu-toggle-reverse)) + (should (equal (key-binding (kbd "s s")) + (lookup-key "s" ergoemacs-test--dired-sort-map))) + (should (equal (key-binding (kbd "s .")) + (lookup-key "." ergoemacs-test--dired-sort-map))) + (should (equal (key-binding (kbd "s t")) + (lookup-key "t" ergoemacs-test--dired-sort-map))) + (should (equal (key-binding (kbd "s n")) + (lookup-key "n" ergoemacs-test--dired-sort-map))) + (should (equal (key-binding (kbd "|")) #'dired-sort-menu-toggle-reverse)) (kill-buffer (current-buffer)) - (remove-hook 'dired-mode-hook (lambda () - (interactive) - (make-local-variable 'dired-sort-map) - (setq dired-sort-map (make-sparse-keymap)) - (define-key dired-mode-map "s" dired-sort-map) - (define-key dired-sort-map "s" - '(lambda () "sort by Size" - (interactive) (dired-sort-other (concat dired-listing-switches "-AlS --si --time-style long-iso")))) - (define-key dired-sort-map "." - '(lambda () "sort by eXtension" - (interactive) (dired-sort-other (concat dired-listing-switches "X")))) - (define-key dired-sort-map "t" - '(lambda () "sort by Time" - (interactive) (dired-sort-other (concat dired-listing-switches "t")))) - (define-key dired-sort-map "n" - '(lambda () "sort by Name" - (interactive) (dired-sort-other (concat dired-listing-switches "")))) - ;; Use "|", not "r". - (define-key dired-mode-map "|" 'dired-sort-menu-toggle-reverse) - ))) + ;; FIXME: This does not restore `dired-mode-map'! + (remove-hook 'dired-mode-hook #'ergoemacs-test--dired-hook)) (ert-deftest ergoemacs-test-quail-translations () diff --git a/ergoemacs-theme-engine.el b/ergoemacs-theme-engine.el index 78accc051f..1f6785e621 100644 --- a/ergoemacs-theme-engine.el +++ b/ergoemacs-theme-engine.el @@ -1,6 +1,6 @@ ;;; ergoemacs-theme-engine.el --- Ergoemacs map interface -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Filename: ergoemacs-theme-engine.el ;; Description: @@ -135,7 +135,7 @@ (message "Wrote current ergoemacs bindings to ~/.inputrc"))) ;;;###autoload -(defalias 'ergoemacs-bash 'ergoemacs-theme-create-bash) +(defalias 'ergoemacs-bash #'ergoemacs-theme-create-bash) (defcustom ergoemacs-function-short-names '((abort-recursive-edit "abort edit") @@ -417,8 +417,7 @@ current buffer." (setq ergoemacs-command-loop--read-key-prompt "")))) (when (arrayp key-list) ;; Compatibility with old calling convention. - (setq key-list (con - s (list key-list) (if up-event (list up-event)))) + (setq key-list (cons (list key-list) (if up-event (list up-event)))) (when buffer (let ((raw (if (numberp buffer) (this-single-command-raw-keys) buffer))) (setf (cdar (last key-list)) raw))) @@ -753,7 +752,7 @@ to png files." "ergoemacs-png-convert" "*ergoemacs-theme-png-convert*" (nth 1 png-info)) ergoemacs-theme--png-last (nth 2 png-info)) - (set-process-sentinel process 'ergoemacs-theme--png--process)))))) + (set-process-sentinel process #'ergoemacs-theme--png--process)))))) (defun ergoemacs-theme--png (&optional layout full-p reread) "Get png file for layout, or create one. diff --git a/ergoemacs-themes.el b/ergoemacs-themes.el index 539661da56..032bed4879 100644 --- a/ergoemacs-themes.el +++ b/ergoemacs-themes.el @@ -1,6 +1,6 @@ ;;; ergoemacs-themes.el --- ErgoEmacs keybindings and themes -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Maintainer: Matthew L. Fidler ;; Authors: Matthew L. Fidler, Xah Lee, Drew Adams @@ -30,15 +30,15 @@ (require 'ibuffer) (defun ergoemacs-global-set-key (key command &optional extra-keys) - "Translates KEY from a 'us' layout to the current layout. + "Translates KEY from a `us' layout to the current layout. This also sets the binding as a global binding as COMMAND. -For example, if your layout is 'us', the command +For example, if your layout is `us', the command - (ergoemaces-global-set-key (kbd \"M-k\") 'next-line) + (ergoemacs-global-set-key (kbd \"M-k\") #\\='next-line) -will bind 'Meta-k' to next-line. If your layout is 'colemak', it will bind -'Meta-e' to next-line. +will bind `Meta-k' to next-line. If your layout is `colemak', it will bind +`Meta-e' to next-line. EXTRA-KEYS are untranslated keys that are appended." (if extra-keys @@ -51,16 +51,16 @@ EXTRA-KEYS are untranslated keys that are appended." command))) (defun ergoemacs-define-key (map key command &optional extra-keys) - "Translates KEY from a 'us' layout to the current layout. + "Translates KEY from a `us' layout to the current layout. In this case, the key is then defined in the MAP to run COMMAND. -For example, if your layout is 'us', the command +For example, if your layout is `us', the command - (ergoemacs-define-key keymap (kbd \"M-k\") 'next-line) + (ergoemacs-define-key keymap (kbd \"M-k\") #\\='next-line) -will bind 'Meta-k' to next-line. If your layout is 'colemak', it will bind -'Meta-e' to next-line. +will bind `Meta-k' to next-line. If your layout is `colemak', it will bind +`Meta-e' to next-line. EXTRA-KEYS are untranslated keys that are appended." (if extra-keys diff --git a/ergoemacs-translate.el b/ergoemacs-translate.el index 31e923155a..cd4499ac6b 100644 --- a/ergoemacs-translate.el +++ b/ergoemacs-translate.el @@ -1,6 +1,6 @@ ;;; ergoemacs-translate.el --- Keyboard translation functions -*- lexical-binding: t -*- -;; Copyright © 2013-2021 Free Software Foundation, Inc. +;; Copyright © 2013-2023 Free Software Foundation, Inc. ;; Filename: ergoemacs-translate.el ;; Description: @@ -122,7 +122,7 @@ hash-f-t))) (defun ergoemacs-translate--emacs-shift (key-seq &optional modifier prefix) - "Uses emacs style shift-translation: M-Q becomes M-q. + "Uses Emacs style shift-translation: M-Q becomes M-q. KEY-SEQ must be a vector. If there is no need to shift-translate the key sequence return nil. @@ -131,7 +131,7 @@ Optionally you can change how this function behaves. Instead of translating the shifted key to the unshifted key, you can remove another modifier. For example if you wanted to -convert C-M-a to C-a, you could use 'meta as the MODIFIER +convert C-M-a to C-a, you could use `meta' as the MODIFIER argument to remove the M- modifier. The PREFIX argument can add a key before the key where the @@ -247,7 +247,7 @@ This will shift translate Alt+# to Alt+3." (not (eq (event-convert-list (list 'shift (setq basic (event-basic-type (aref key 0))))) (ergoemacs-translate--event-convert-list (list 'ergoemacs-shift basic))))) (setq ergoemacs-translate--define-key-if-defined-p nil - ergoemacs-translate--define-key-replacement-function 'ergoemacs-command-loop--shift-translate) + ergoemacs-translate--define-key-replacement-function #'ergoemacs-command-loop--shift-translate) (vector (ergoemacs-translate--event-convert-list (append modifiers (list 'ergoemacs-shift basic))))))) (defun ergoemacs-translate--ergoemacs-timeout (key) @@ -266,7 +266,7 @@ seleceted (instead of copying the text)." (memq 'ergoemacs-shift modifiers)))) (setq basic (ergoemacs-translate--event-basic-type (aref key 0)) ergoemacs-translate--define-key-if-defined-p nil - ergoemacs-translate--define-key-replacement-function 'ergoemacs-command-loop--shift-timeout) + ergoemacs-translate--define-key-replacement-function #'ergoemacs-command-loop--shift-timeout) (vector (ergoemacs-translate--event-convert-list (append modifiers (list 'shift basic))))))) (defun ergoemacs-translate--to-string (key) @@ -355,8 +355,8 @@ This uses `ergoemacs-translate--apply-key'" (defun ergoemacs-translate--event-modifiers (event &optional layout) "Return a list of symbols representing the modifier keys in event EVENT. This is different than `event-modifiers' in two ways: -- Symbol keys like # will return 'ergoemacs-shift for a QWERTY keyboard. -- Special keys like C-RET will return 'ergoemacs-control +- Symbol keys like # will return `ergoemacs-shift' for a QWERTY keyboard. +- Special keys like C-RET will return `ergoemacs-control' LAYOUT is the keyboard layout." (let ((modifiers (event-modifiers event)) tmp @@ -407,7 +407,7 @@ MODIFIERS is the precalculated modifiers from `ergoemacs-translate--event-modifiers'." (if (vectorp event) (progn - (apply 'vector (mapcar (lambda(x) (ergoemacs-translate--event-layout x layout-to layout-from basic modifiers)) event))) + (apply #'vector (mapcar (lambda(x) (ergoemacs-translate--event-layout x layout-to layout-from basic modifiers)) event))) (let* ((basic (or basic (ergoemacs-translate--event-basic-type event layout-from))) (modifiers (or modifiers (ergoemacs-translate--event-modifiers event layout-from))) new-modifiers @@ -450,9 +450,9 @@ This also translates <C-i> to ?i, <C-m> to ?m <C-[> to ?[ (defun ergoemacs-translate--event-convert-list (list &optional layout) "Convert the event description LIST to an event type. This is different than `event-convert-list' because: - - '(shift ?3) or '(ergoemacs-shift ?3) produces ?# on a QWERTY LAYOUT. - - '(ergoemacs-control control ?m) produces C-RET - - '(ergoemacs-gui control ?m) produces <C-m>. this applies for ?i and ?[ as well. + - (shift ?3) or (ergoemacs-shift ?3) produces ?# on a QWERTY LAYOUT. + - (ergoemacs-control control ?m) produces C-RET + - (ergoemacs-gui control ?m) produces <C-m>. this applies for ?i and ?[ as well. - Mouse events allow click modifiers" (let ((cur-list list) elt @@ -759,9 +759,9 @@ When NAME is a symbol, setup the translation function for the symbol." (dolist (type '("-universal-argument" "-negative-argument" "-digit-argument" "-modal")) (fset (intern (concat "ergoemacs-translate--" name-str type)) - 'ergoemacs-translate--setup-command-loop) + #'ergoemacs-translate--setup-command-loop) (fset (intern (concat "ergoemacs-" name-str type)) - 'ergoemacs-translate--setup-command-loop) + #'ergoemacs-translate--setup-command-loop) (when (string= type "-universal-argument") (cl-pushnew (intern (concat "ergoemacs-" name-str type)) ergoemacs-command-loop--universal-functions) (cl-pushnew (intern (concat "ergoemacs-translate--" name-str type)) ergoemacs-command-loop--universal-functions)))))) @@ -1100,10 +1100,10 @@ This takes into consideration the modal state of `ergoemacs-mode'." (defun ergoemacs-translate--ahk-ini (&optional all-layouts all-themes) "Creates the ini file used with the autohotkey script." - (let ((layouts (or (and all-layouts (sort (ergoemacs-layouts--list) 'string<)) + (let ((layouts (or (and all-layouts (sort (ergoemacs-layouts--list) #'string<)) (and (eq (ergoemacs :layout) 'ergoemacs-layout-us) (list "us")) (list "us" ergoemacs-keyboard-layout))) - (themes (or (and all-themes (sort (ergoemacs-theme--list) 'string<)) + (themes (or (and all-themes (sort (ergoemacs-theme--list) #'string<)) (list ergoemacs-theme))) (original-layout ergoemacs-keyboard-layout) (original-theme ergoemacs-theme)