GithubHelp home page GithubHelp logo

Comments (1)

xparq avatar xparq commented on July 25, 2024

OK, so this means I really can't use Esc as this nice quick exit function in conemacs :-/

Alt+Q is kinda viable, fill-paragraph is the cost...
So, conemacs is now:

emacs -nw --eval '(define-key (current-global-map) (kbd "M-q") (kbd "C-x C-c"))' -- "$@"

Well, not so fast....

Actually, even my vanilla Emacs 30 seems to use that key by default in .sh mode, overriding the global map... Noice...:

"Keymap precedence is honestly one of the messiest parts of Emacs users are exposed to, in my opinion, especially when it comes to modal maps."

So, WTF should I do now?

-> https://emacs.stackexchange.com/questions/352/how-to-override-major-mode-bindings/358

The new conemacs:

#!/bin/sh

basedir=`dirname $0`

# Map custom key to quit, and prevent it from being overridden by every random mode
emacs -nw -l $basedir/force-map-quit-key.el -- "$@"

force-map-quit-key.el:

;; https://emacs.stackexchange.com/a/358/41263

;; Facilitate defining key bindings with high(est) priority
;; https://github.com/kaushalmodi/.emacs.d/blob/master/elisp/modi-mode.el

(defvar sz/forced-keymap (make-sparse-keymap)
  "High-precedence keymap for 'sticky' bindings.")

;;;###autoload
(define-minor-mode sz/forced-keymap-mode
  "A minor mode for key bindings to override major (and most minor) modes."
  ;; If init-value is not set to t, this mode does not get enabled in
  ;; `fundamental-mode' buffers even after doing \"(sz/global-forced-keymap-mode 1)\".
  ;; More info: http://emacs.stackexchange.com/q/16693/115
  :init-value t
  :lighter " sz/forced-keymap-mode"
  :keymap sz/forced-keymap)

;;;###autoload
(define-globalized-minor-mode sz/global-forced-keymap-mode
                              sz/forced-keymap-mode
                              sz/forced-keymap-mode)

;; https://github.com/jwiegley/use-package/blob/master/bind-key.el
;; The keymaps in `emulation-mode-map-alists' take precedence over
;; `minor-mode-map-alist'
(add-to-list 'emulation-mode-map-alists `((sz/forced-keymap-mode . ,sz/forced-keymap)))

;; Turn off the minor mode in the minibuffer
(defun turn-off-my-mode ()
  "Turn off sz/forced-keymap-mode."
  (sz/forced-keymap-mode -1))
(add-hook 'minibuffer-setup-hook #'turn-off-my-mode)

(provide 'sz/forced-keymap-mode)

;; Minor mode tutorial: http://nullprogram.com/blog/2013/02/06/

;;------------------------------------------------------------------------------
(define-key sz/forced-keymap (kbd "M-q") #'save-buffers-kill-terminal)
;; Just a key macro (alias) here didn't work if there were changes to save! :-o
;; It got stuck in some input mode with no prompt or echo...:
;;      ... (kbd "C-x C-c"))

from .emacs.d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.