branch: externals/ergoemacs-mode commit 69abf8d47c1ee2cd746292948b413d7feeae0baf Author: Matthew Fidler <514778+mattfid...@users.noreply.github.com> Commit: Matthew Fidler <514778+mattfid...@users.noreply.github.com>
Fix ergoemacs-calculate-bindings --- ergoemacs-calculate-bindings.el | 148 ++++++++++++++++++++++++++++++++++++++++ ergoemacs-theme-engine.el | 61 ++++------------- ergoemacs-themes.el | 92 +++++++++++++++++-------- 3 files changed, 227 insertions(+), 74 deletions(-) diff --git a/ergoemacs-calculate-bindings.el b/ergoemacs-calculate-bindings.el new file mode 100644 index 0000000..b11f0a0 --- /dev/null +++ b/ergoemacs-calculate-bindings.el @@ -0,0 +1,148 @@ +;;; ergoemacs-calculate-bindings.el --- Keyboard keybinding translation -*- lexical-binding: t -*- + +;; Copyright © 2013-2021 Free Software Foundation, Inc. + +;; Filename: ergoemacs-translate.el +;; Description: +;; Author: Matthew L. Fidler +;; Maintainer: +;; Created: Sat Sep 28 20:08:09 2013 (-0500) +;; Version: +;; Last-Updated: +;; By: +;; Update #: 0 +;; URL: +;; Doc URL: +;; Keywords: +;; Compatibility: +;; +;; Features that might be required by this library: +;; +;; None +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Commentary: +;; +;; +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Change Log: +;; +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation; either version 3, or +;; (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;;; Code: +(defcustom ergoemacs-lookup-bindings-list + '(("C-x o" other-window) + ("C-b" backward-char) + ("C-f" forward-char) + ("M-b" backward-word) + ("M-f" foward-word) + ("C-p" previous-line) + ("C-n" next-line) + ("M-s o" occur) + ("C-SPC" set-mark-command) + ("DEL" delete-backward-char) + ("C-d" delete-char ) + ("M-d" kill-word) + ("M-DEL" backward-kill-word) + ("M-{" backward-paragraph) + ("M-}" forward-paragraph) + ("M-{" ergoemacs-backward-block) + ("M-}" ergoemacs-forward-block) + ("C-e" ergoemacs-end-of-line-or-what) + ("C-a" ergoemacs-beginning-of-line-or-what) + ("C-e" ergoemacs-end-of-line-or-what) + ("C-a" move-beginning-of-line) + ("C-e" move-end-of-line) + ("C-v" scroll-down-command) + ("M-v" scroll-up-command) + ("<begin>" beginning-of-buffer) + ("<C-end>" end-of-buffer) + ("C-M-b" ergoemacs-backward-open-bracket) + ("C-M-f" ergoemacs-backward-open-bracket) + ("M-w" ergoemacs-copy-line-or-region) + ("C-y" ergoemacs-paste) + ("M-y" ergoemacs-paste-cycle) + ("C-_" ergoemacs-undo) + ;("C-/" ergoemacs-undo) + ("M-%" query-replace) + ("C-s" isearch-forward) + ("C-M-s" isearch-forward-regexp) + ("C-r" isearch-backward) + ("C-M-r" isearch-backward-regexp) + ("C-x 1" delete-other-windows) + ("C-x 0" delete-window) + ("C-x 2" split-window-below) + ("C-x 3" split-window-right) + ("C-x b" switch-to-buffer) + ("C-x C-b" ibuffer) + ("C-x C-b" execute-extended-command) + ("C-k" kill-line) + ("M-TAB" ergoemacs-call-keyword-completion)) + "Ergoemacs short command names." + :group 'ergoemacs-themes + :type '(repeat :tag "Command abbreviation" + (list + (string :tag "original keybinding in Emacs") + (sexp :tag "Ergoemacs Command")))) + +(defvar ergoemacs-override-keymap) +(defvar ergoemacs-keyboard-layout) + +(declare-function ergoemacs-translate--event-layout "ergoemacs-translate") + +(defun ergoemacs-calculate-bindings-for-current-binding (keymap space) + "Calculate ergoemcs keybindings for a KEYMAP and dislay in another buffer. +SPACE represents the amount of sacing to add" + (dolist (elt ergoemacs-lookup-bindings-list) + (let* ((command (nth 1 elt)) + (key (nth 0 elt)) + (key-code (read-kbd-macro key)) + (bind (lookup-key (symbol-value keymap) key-code)) + ergoemacs-command) + (when bind + (dolist (ergoemacs-command (where-is-internal command ergoemacs-override-keymap nil t t)) + (insert (format "%s(ergoemacs-define-key %s (kbd \"%s\") '%s)" space (symbol-name keymap) + (key-description (ergoemacs-translate--event-layout ergoemacs-command "us" ergoemacs-keyboard-layout)) + (symbol-name bind)))))))) + + +(defvar ergoemacs-calculate-bindings-for-both-theme--tmp nil) +(defun ergoemacs-calculate-bindings-for-both-themes (keymap) + (setq ergoemacs-calculate-bindings-for-both-theme--tmp + (copy-keymap ergoemacs-override-keymap) + ergoemacs-override-keymap (make-sparse-keymap)) + (let ((buf (get-buffer-create (format "*ergoemacs keybindings for keymap %s*" keymap)))) + (with-output-to-temp-buffer buf + (with-current-buffer buf + (insert "(if (string-equal ergoemacs-theme \"reduction\")\n (progn") + (ergoemacs-install-reduction-theme) + (ergoemacs-calculate-bindings-for-current-binding keymap "\n ") + (insert ")") + (setq ergoemacs-override-keymap (make-sparse-keymap)) + (ergoemacs-install-standard-theme) + (ergoemacs-calculate-bindings-for-current-binding keymap "\n ") + (insert ")")))) + (setq ergoemacs-override-keymap ergoemacs-calculate-bindings-for-both-theme--tmp + ergoemacs-calculate-bindings-for-both-theme--tmp nil)) + +(provide 'ergoemacs-calculate-bindings) +;;; ergoemacs-calculate-binding.el ends here diff --git a/ergoemacs-theme-engine.el b/ergoemacs-theme-engine.el index 2aa9fa9..7baf026 100644 --- a/ergoemacs-theme-engine.el +++ b/ergoemacs-theme-engine.el @@ -357,10 +357,8 @@ should insert the face name." ;;;###autoload (defalias 'ergoemacs-bash 'ergoemacs-theme-create-bash) - (defcustom ergoemacs-function-short-names - '( - (abort-recursive-edit "abort edit") + '((abort-recursive-edit "abort edit") (ace-jump-mode "ace jump") (backward-char "← char") (back-to-indentation "← indent") @@ -542,8 +540,7 @@ should insert the face name." (if (stringp (car elt)) (if (string= (car elt) "SPC") (setq key " ") - (setq key "f#") - ) + (setq key "f#")) (setq key (nth (car elt) layout))) (if (string= key "") "" (if (string= key "f#") @@ -554,14 +551,12 @@ should insert the face name." (when (equal key [27]) (setq no-push-p t)) (when ergoemacs-theme--svg-prefix - (setq key (vconcat ergoemacs-theme--svg-prefix key)) - ) + (setq key (vconcat ergoemacs-theme--svg-prefix key))) (setq binding (or (lookup-key ergoemacs-override-keymap key) ;; TODO: Use only the ergoemacs global map, ;; not the regular map? - (lookup-key (current-global-map) key) - ) + (lookup-key (current-global-map) key)) ) (when (integerp binding) (setq binding nil)) @@ -576,11 +571,8 @@ should insert the face name." (or (progn (setq key (assoc ergoemacs-M-O-binding ergoemacs-function-short-names)) - (nth 1 key) - ) - "" - ) - ) + (nth 1 key)) + "")) ;; Regular bindings (and binding (setq key (assoc binding ergoemacs-function-short-names)) @@ -588,13 +580,9 @@ should insert the face name." ;; Unknown binding (and binding (ergoemacs-theme--svg-elt-nonabbrev binding)) - "" - ) - ) - ) + ""))) ((memq elt '(meta control)) - (concat (ergoemacs-key-description--modifier elt) (format " == %s" elt)) - ) + (concat (ergoemacs-key-description--modifier elt) (format " == %s" elt))) ((memq elt '(meta-shift control-shift)) (setq elt (intern (replace-regexp-in-string "-shift" "" (symbol-name elt)))) (concat (ergoemacs-key-description--modifier elt) @@ -605,20 +593,11 @@ should insert the face name." (or (and ergoemacs-theme--svg-prefix (concat " for " (ergoemacs-key-description ergoemacs-theme--svg-prefix))) - "" - ) - ) - ) + ""))) (t (setq key (format "%s" elt)) (when (<= 10 (length key)) - (setq key (concat (substring key 0 10) "…")) - ) - key - ) - ) - ) - ) - ) + (setq key (concat (substring key 0 10) "…"))) + key))))) (defun ergoemacs-theme--svg (&optional layout full-p reread) "Creates SVG based THEME and LAYOUT" @@ -709,10 +688,8 @@ should insert the face name." (push (list (match-string 2) 'control) ergoemacs-theme--svg)) (t (push (list (string-to-number (match-string 2)) 'control) ergoemacs-theme--svg)))) - (t (push nil ergoemacs-theme--svg)) - ) - (setq pt (match-end 0)) - ) + (t (push nil ergoemacs-theme--svg))) + (setq pt (match-end 0))) (push (buffer-substring pt (point-max)) ergoemacs-theme--svg)) (setq ergoemacs-theme--svg (reverse ergoemacs-theme--svg))) (setq ergoemacs-theme--svg-prefixes nil @@ -723,11 +700,7 @@ should insert the face name." ((stringp w) (insert w)) (t - (insert ">" (ergoemacs-theme--svg-elt w layout lay) "<") - ) - ) - ) - ) + (insert ">" (ergoemacs-theme--svg-elt w layout lay) "<"))))) (push file-name ret) (unless full-p (setq ergoemacs-theme--svg-prefixes nil)) @@ -751,11 +724,7 @@ should insert the face name." (setq ergoemacs-keyboard-layout old-layout) ;; TODO: Is this OK? (ergoemacs-mode-reset))) - ret - ) - ) - ) - ) + ret)))) (defvar ergoemacs-theme--png nil) (defvar ergoemacs-theme--png-last nil) diff --git a/ergoemacs-themes.el b/ergoemacs-themes.el index d5ccfa6..2296971 100644 --- a/ergoemacs-themes.el +++ b/ergoemacs-themes.el @@ -316,8 +316,6 @@ Call this before calling any other ergoemacs-set-* function" (global-unset-key (kbd "C-l")) (global-unset-key (kbd "C-k")) (global-unset-key (kbd "M-;")) - - (ergoemacs-unset-keys-in-map isearch-mode-map) ) ;;; Fixed components @@ -375,9 +373,7 @@ These keys do not depend on the layout." (global-set-key (kbd "C-S-o") 'ergoemacs-open-in-external-app) (global-set-key (kbd "C-S-t") 'ergoemacs-open-last-closed) - ;; These go into the isearch-mode-map, which supercedes all other - ;; maps when in isearch mode. - (define-key isearch-mode-map (kbd "C-f") 'isearch-repeat-forward)) + ) (defun ergoemacs-set-help (keymap) "Help change for ergoemacs-mode for KEYMAP." @@ -403,9 +399,7 @@ These keys do not depend on the layout." (ergoemacs-define-key keymap (kbd "<M-delete>") 'kill-word) (ergoemacs-global-set-key (kbd "<M-up>") 'ergoemacs-backward-block) - (ergoemacs-global-set-key (kbd "<M-down>") 'ergoemacs-forward-block) - - (ergoemacs-define-key isearch-mode-map (kbd "M-d") 'isearch-delete-char)) + (ergoemacs-global-set-key (kbd "<M-down>") 'ergoemacs-forward-block)) (defun ergoemacs-set-move-extra-reduction (keymap) "Extra reduction keys with KEYMAP." @@ -440,10 +434,7 @@ These keys do not depend on the layout." (defun ergoemacs-set-move-buffer (keymap) "Move by buffer in KEYMAP." (ergoemacs-define-key keymap (kbd "M-n") 'beginning-of-buffer) - (ergoemacs-define-key keymap (kbd "M-N") 'end-of-buffer) - - (ergoemacs-define-key isearch-mode-map (kbd "M-n") 'isearch-beginning-of-buffer) - (ergoemacs-define-key isearch-mode-map (kbd "M-N") 'isearch-end-of-buffer)) + (ergoemacs-define-key keymap (kbd "M-N") 'end-of-buffer)) (defun ergoemacs-set-move-bracket (keymap) "Move By Bracket for KEYMAP." @@ -474,11 +465,7 @@ These keys do not depend on the layout." (vconcat (listify-key-sequence (kbd "M-z"))))) (ergoemacs-define-key keymap (kbd "C-S-x") 'execute-extended-command) - ;; Mode specific changes - (ergoemacs-define-key isearch-mode-map (kbd "M-c") 'isearch-yank-word-or-char) - (ergoemacs-define-key isearch-mode-map (kbd "M-v") 'ergoemacs-paste) - (ergoemacs-define-key isearch-mode-map (kbd "M-V") 'ergoemacs-paste-cycle) - (define-key isearch-mode-map (kbd "C-v") 'ergoemacs-paste)) + ) (defun ergoemacs-set-search (keymap) "Search and Replace for KEYMAP." @@ -507,7 +494,7 @@ These keys do not depend on the layout." ;; (vconcat (listify-key-sequence (kbd "M-;"))) ;; ) ;; ) - (ergoemacs-define-key isearch-mode-map (kbd "M-:") 'isearch-repeat-backward) + ;; (ergoemacs-define-key isearch-mode-map (kbd "M-:") 'isearch-repeat-backward) ;; (put 'isearch-repeat-backward ;; :advertised-binding (ergoemacs-translate--event-layout ;; (vconcat (listify-key-sequence (kbd "M-:"))) @@ -519,7 +506,7 @@ These keys do not depend on the layout." ;; Ergoemacs does not have a generic "edit this" function. So I ;; used C-x C-q, since that is used to make uneditable things ;; editable. - (define-key isearch-mode-map (kbd "C-x C-q") 'isearch-edit-string) + ;; (define-key isearch-mode-map (kbd "C-x C-q") 'isearch-edit-string) ;; When editing a search in isearch, it uses the ;; minibuffer-local-isearch-map keymap, which gets overridden by the @@ -546,7 +533,7 @@ These keys do not depend on the layout." ;; it ends up breaking commands that exit isearch. For example, ;; trying to go to the beginning of a line will terminate the ;; search, but not also go to the beginning of the line. - (ergoemacs-define-key isearch-mode-map (kbd "M-h") 'isearch-repeat-forward) + ;; (ergoemacs-define-key isearch-mode-map (kbd "M-h") 'isearch-repeat-forward) ;; Changing advertised-binding does not work. Maybe because it is ;; only defined within isearch-mode-map? @@ -555,7 +542,7 @@ These keys do not depend on the layout." ;; (vconcat (listify-key-sequence (kbd "M-;"))) ;; ) ;; ) - (ergoemacs-define-key isearch-mode-map (kbd "M-y") 'isearch-repeat-backward) + ;; (ergoemacs-define-key isearch-mode-map (kbd "M-y") 'isearch-repeat-backward) ;; (put 'isearch-repeat-backward ;; :advertised-binding (ergoemacs-translate--event-layout ;; (vconcat (listify-key-sequence (kbd "M-:"))) @@ -567,7 +554,7 @@ These keys do not depend on the layout." ;; Ergoemacs does not have a generic "edit this" function. So I ;; used C-x C-q, since that is used to make uneditable things ;; editable. - (define-key isearch-mode-map (kbd "<f2>") 'isearch-edit-string) + ;; (define-key isearch-mode-map (kbd "<f2>") 'isearch-edit-string) ;; When editing a search in isearch, it uses the ;; minibuffer-local-isearch-map keymap, which gets overridden by the @@ -576,6 +563,7 @@ These keys do not depend on the layout." (define-key minibuffer-local-isearch-map [remap isearch-forward] 'isearch-forward-exit-minibuffer) (define-key minibuffer-local-isearch-map [remap isearch-backward] 'isearch-reverse-exit-minibuffer)) + (defun ergoemacs-set-switch (keymap) "Window/Frame/Tab Switching for KEYMAP." (ergoemacs-define-key keymap (kbd "M-s") 'other-window) @@ -645,8 +633,9 @@ These keys do not depend on the layout." ;; Hard-wrap/un-hard-wrap paragraph (ergoemacs-define-key keymap (kbd "M-q") 'ergoemacs-compact-uncompact-block) - (ergoemacs-define-key isearch-mode-map (kbd "M-?") 'isearch-toggle-regexp) - (ergoemacs-define-key isearch-mode-map (kbd "M-/") 'isearch-toggle-case-fold)) + ;; (ergoemacs-define-key isearch-mode-map (kbd "M-?") 'isearch-toggle-regexp) + ;; (ergoemacs-define-key isearch-mode-map (kbd "M-/") 'isearch-toggle-case-fold) + ) (defun ergoemacs-set-select-items (keymap) "Select Items for KEYMAP." @@ -695,9 +684,7 @@ These keys do not depend on the layout." (ergoemacs-define-key keymap (kbd "<apps> r") 'goto-map) ;; Already in CUA) (ergoemacs-define-key keymap (kbd "<apps> SPC") 'set-mark-command) (ergoemacs-define-key keymap (kbd "<apps> a") 'mark-whole-buffer) - ;; (kbd "<apps> d") ("C-x" :ctl-to-alt) - ;; (kbd "<apps> f") ("C-c" :unchorded-ctl) - + (ergoemacs-define-key ergoemacs-override-keymap (kbd "<apps> f") (lambda () @@ -1303,6 +1290,53 @@ In a terminal, this can be either arrow keys (e.g. meta+O A == <up>) or regular (defvar ergoemacs-override-keymap) +(defun ergoemacs-install-isearch-mode () + "Installs keys for isearch mode." + (ergoemacs-unset-keys-in-map isearch-mode-map) + ;; Mode specific changes + ;; (ergoemacs-define-key isearch-mode-map (kbd "M-d") 'isearch-delete-char) + + ;; (ergoemacs-define-key isearch-mode-map (kbd "M-c") 'isearch-yank-word-or-char) + ;; (ergoemacs-define-key isearch-mode-map (kbd "M-v") 'ergoemacs-paste) + ;; (ergoemacs-define-key isearch-mode-map (kbd "M-V") 'ergoemacs-paste-cycle) + ;; (define-key isearch-mode-map (kbd "C-v") 'ergoemacs-paste) + (if (string-equal ergoemacs-theme "reduction") + (progn + (ergoemacs-define-key isearch-mode-map (kbd "C-M-:") 'isearch-occur) + (ergoemacs-define-key isearch-mode-map (kbd "M-d") 'isearch-delete-char) + (ergoemacs-define-key isearch-mode-map (kbd "DEL") 'isearch-delete-char) + (ergoemacs-define-key isearch-mode-map (kbd "<menu> v") 'isearch-yank-kill) + (ergoemacs-define-key isearch-mode-map (kbd "M-v") 'isearch-yank-kill) + (ergoemacs-define-key isearch-mode-map (kbd "C-v") 'isearch-yank-kill) + (ergoemacs-define-key isearch-mode-map (kbd "<S-insert>") 'isearch-yank-kill) + (ergoemacs-define-key isearch-mode-map (kbd "M-V") 'isearch-yank-pop) + (ergoemacs-define-key isearch-mode-map (kbd "C-S-v") 'isearch-yank-pop) + (ergoemacs-define-key isearch-mode-map (kbd "<menu> 5") 'isearch-query-replace) + (ergoemacs-define-key isearch-mode-map (kbd "M-5") 'isearch-query-replace) + (ergoemacs-define-key isearch-mode-map (kbd "M-h") 'isearch-repeat-forward) + (ergoemacs-define-key isearch-mode-map (kbd "C-e") 'isearch-repeat-forward) + (ergoemacs-define-key isearch-mode-map (kbd "C-M-d") 'isearch-repeat-forward) + (ergoemacs-define-key isearch-mode-map (kbd "M-y") 'isearch-repeat-backward) + (ergoemacs-define-key isearch-mode-map (kbd "C-M-s") 'isearch-repeat-backward) + (ergoemacs-define-key isearch-mode-map (kbd "M-t") 'isearch-complete)) + (ergoemacs-define-key isearch-mode-map (kbd "M-n") 'isearch-beginning-oef-buffer) + (ergoemacs-define-key isearch-mode-map (kbd "M-N") 'isearch-end-of-buffer) + (ergoemacs-define-key isearch-mode-map (kbd "C-M-:") 'isearch-occur) + (ergoemacs-define-key isearch-mode-map (kbd "M-d") 'isearch-delete-char) + (ergoemacs-define-key isearch-mode-map (kbd "DEL") 'isearch-delete-char) + (ergoemacs-define-key isearch-mode-map (kbd "M-v") 'isearch-yank-kill) + (ergoemacs-define-key isearch-mode-map (kbd "C-v") 'isearch-yank-kill) + (ergoemacs-define-key isearch-mode-map (kbd "<S-insert>") 'isearch-yank-kill) + (ergoemacs-define-key isearch-mode-map (kbd "M-V") 'isearch-yank-pop) + (ergoemacs-define-key isearch-mode-map (kbd "C-S-v") 'isearch-yank-pop) + (ergoemacs-define-key isearch-mode-map (kbd "M-5") 'isearch-query-replace) + (ergoemacs-define-key isearch-mode-map (kbd "M-;") 'isearch-repeat-forward) + (ergoemacs-define-key isearch-mode-map (kbd "C-e") 'isearch-repeat-forward) + (ergoemacs-define-key isearch-mode-map (kbd "C-M-d") 'isearch-repeat-forward) + (ergoemacs-define-key isearch-mode-map (kbd "C-M-s") 'isearch-repeat-backward) + (ergoemacs-define-key isearch-mode-map (kbd "M-t") 'isearch-complete))) + + (defun ergoemacs-install-reduction-theme () "Install reduction theme." (ergoemacs-unset-keys) @@ -1330,6 +1364,8 @@ In a terminal, this can be either arrow keys (e.g. meta+O A == <up>) or regular (ergoemacs-set-select-items ergoemacs-override-keymap) (ergoemacs-fix-arrow-keys ergoemacs-override-keymap) (ergoemacs-set-apps ergoemacs-override-keymap) + + (ergoemacs-install-isearch-mode) (ergoemacs-set-remaps) (ergoemacs-set-quit) @@ -1364,7 +1400,7 @@ In a terminal, this can be either arrow keys (e.g. meta+O A == <up>) or regular (ergoemacs-set-text-transform ergoemacs-override-keymap) (ergoemacs-set-select-items ergoemacs-override-keymap) (ergoemacs-fix-arrow-keys ergoemacs-override-keymap) - + (ergoemacs-install-isearch-mode) (ergoemacs-set-remaps) (ergoemacs-set-quit) (ergoemacs-set-menu-bar-help)