Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: WTH is going on with Alt+X? It quits... #7

Closed
3 tasks done
xparq opened this issue Aug 25, 2023 · 1 comment
Closed
3 tasks done

Fix: WTH is going on with Alt+X? It quits... #7

xparq opened this issue Aug 25, 2023 · 1 comment

Comments

@xparq
Copy link
Owner

xparq commented Aug 25, 2023

...while C-h k says that C-x C-c x is undefined! :-o

  • Why the hell is C-x C-c x the same as Alt+X
    -> Only in console mode -- not in the normal config!
    • Because a) Esc is remapped in conemacs to C-x C-c and b) Alt = Esc to the idiotic terminal stuff... :-/
  • Why does it quit? Is it related to redefining ESC?
    ->It's the proper exit command, with confirmations etc., so probably! But doesn't happen in GUI mode!
    • Same thing: Alt = Esc in the terminal :-/
  • Why is it "undefined" (then)???
    • Because it is..., now that "Alt" (i.e. "Esc"!) has been redefined to C-x C-c...

Yet another sad case of terminal key translation fukup! :-/ -> #8
(Confirmed by e.g. the default Alt+Q also quitting.)

@xparq
Copy link
Owner Author

xparq commented Aug 25, 2023

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"))

@xparq xparq closed this as completed Aug 25, 2023
@xparq xparq reopened this Aug 25, 2023
@xparq xparq closed this as completed in a268659 Aug 25, 2023
xparq added a commit that referenced this issue Aug 25, 2023
Fix #7 -- such a depressing "journey" to a convoluted solution though!...
@xparq xparq changed the title WTH is going on with Alt+X? It quits... Fix: WTH is going on with Alt+X? It quits... Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant