[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: POLL: make C-x o transient

From: Juri Linkov
Subject: Re: POLL: make C-x o transient
Date: Mon, 25 Jan 2021 19:01:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>> Which will make `C-x o` invoke a transient version of `other-window'
>> like `text-scale-adjust’ does.
> I think the pattern is clear: `C-x <letter>` are good candidates ;-)

And non-letters too, especially `C-x {`, `C-x }`, `C-x ^`, ...
need to be repeatable.  I'm using such quite messy blob of code,
it would be nice if someone would generalize this mess
without using advice-add.

#+begin_src emacs-lisp
(defvar window-command-keymap
  (let ((map (make-sparse-keymap)))
    ;; Standard keys:
    (define-key map "0" 'delete-window)
    (define-key map "1" 'delete-other-windows)
    (define-key map "2" 'split-window-below)
    (define-key map "3" 'split-window-right)
    (define-key map "o" 'other-window)
    (define-key map "^" 'enlarge-window)
    (define-key map "}" 'enlarge-window-horizontally)
    (define-key map "{" 'shrink-window-horizontally)
    (define-key map "-" 'shrink-window-if-larger-than-buffer)
    (define-key map "+" 'balance-windows)
    ;; Additional keys:
    (define-key map "v"     'shrink-window)
    (define-key map [down]  'shrink-window)
    (define-key map [up]    'enlarge-window)
    (define-key map [left]  'shrink-window-horizontally)
    (define-key map [right] 'enlarge-window-horizontally)
  "Keymap for commands that operate on windows.")

(advice-add 'enlarge-window-horizontally
            :after (lambda (&rest _args)
                     (set-transient-map window-command-keymap)))
(advice-add 'shrink-window-horizontally
            :after (lambda (&rest _args)
                     (set-transient-map window-command-keymap)))
(advice-add 'enlarge-window
            :after (lambda (&rest _args)
                     (set-transient-map window-command-keymap)))
(advice-add 'shrink-window
            :after (lambda (&rest _args)
                     (set-transient-map window-command-keymap)))
(defun window-command-prefix ()
  (message "Use window prefix keys...")
  (set-transient-map window-command-keymap))
(define-key ctl-x-map "wr" window-command-prefix)

;; (define-key window-command-keymap [digit-argument] 'ignore)
;; (define-key window-command-keymap [universal-argument] 'ignore)
;; (define-key window-command-keymap [?\C-u] 'universal-argument)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]