Changing window faster in Emacs (or repeating last shortcut with a single strike)

后端 未结 4 1474
無奈伤痛
無奈伤痛 2021-01-05 14:23

if I want to change windows in emacs I do C-x o and that\'s fine with me...but when I want to change window lots of times in a row C-x o is not so convenient...is there a wa

4条回答
  •  青春惊慌失措
    2021-01-05 15:14

    I use C-tab to switch windows:

    (global-set-key [C-tab] 'other-window)
    

    Holding down the Control key, you can jump windows repeatedly just by hitting the tab key.

    EDIT: my original answer contained the following

    I don't think there's a built-in way to repeat last command for basic commands like this ...

    This is no longer true. Emacs now contains repeat.el, which allows for exactly the behaviour rabidmachine9 asked for.

    The following code will create a repeating other-window, such that after pressing C-x o the first time, pressing o afterwards will continue moving to the next window.

    (require 'repeat)
    (defun make-repeatable-command (cmd)
      "Returns a new command that is a repeatable version of CMD.
    The new command is named CMD-repeat.  CMD should be a quoted
    command.
    
    This allows you to bind the command to a compound keystroke and
    repeat it with just the final key.  For example:
    
      (global-set-key (kbd \"C-c a\") (make-repeatable-command 'foo))
    
    will create a new command called foo-repeat.  Typing C-c a will
    just invoke foo.  Typing C-c a a a will invoke foo three times,
    and so on.
    
    See related discussion here: 
    http://batsov.com/articles/2012/03/08/emacs-tip-number-4-repeat-last-command/#comment-459843643
    https://groups.google.com/forum/?hl=en&fromgroups=#!topic/gnu.emacs.help/RHKP2gjx7I8"
      (fset (intern (concat (symbol-name cmd) "-repeat"))
            `(lambda ,(help-function-arglist cmd) ;; arg list
               ,(format "A repeatable version of `%s'." (symbol-name cmd)) ;; doc string
               ,(interactive-form cmd) ;; interactive form
               ;; see also repeat-message-function
               (setq last-repeatable-command ',cmd)
               (repeat nil)))
      (intern (concat (symbol-name cmd) "-repeat")))
    
    (global-set-key (kbd "C-x o") (make-repeatable-command 'other-window))
    

    The function make-repeatable-command than then be used to create other repeating commands, using the same template.

提交回复
热议问题