Emacs key binding fallback

前端 未结 3 860
天命终不由人
天命终不由人 2020-12-06 11:42

I have a minor mode. If that mode is active and the user hits DEL, I want to do some action, but only if some condition holds. If the condition holds and the action is execu

3条回答
  •  情话喂你
    2020-12-06 12:15

    This is what I use for my smart-tab package which does exactly that.

    (defun smart-tab-default ()
      "Indents region if mark is active, or current line otherwise."
      (interactive)
      (if mark-active
          (indent-region (region-beginning)
                         (region-end))
    
        (call-interactively
         (or
          ;; Minor mode maps for tab (without smart-tab-mode)
          (cdar (assq-delete-all 'smart-tab-mode (minor-mode-key-binding "\t")))
          (cdar (assq-delete-all 'smart-tab-mode (minor-mode-key-binding [(tab)])))
          (local-key-binding "\t")
          (local-key-binding [(tab)])
          (global-key-binding "\t")
          (global-key-binding [(tab)])))))
    

    And in the command smart-tab (which is the one bound to tab in the minor mode), it has the following:

    (if (smart-tab-must-expand prefix)
        ;; use smart tab
      (smart-tab-default))
    

    It first checks if there are any minor mode bindings for tab (not including smart-tab-mode), then local, and finally global keybindings.

提交回复
热议问题