From 274b6fd8bf998278ae78f13c0e3f3258cc3f8191 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 25 Aug 2021 23:44:10 -0500 Subject: Change disabled-command-function and disable commands I want to be able to do anything, but some commands are bound to keys that I hit all the time and it's annoying. So I've disabled them but changed the `disabled-key-function' to check whether I've passed the command with M-x or using the dumb keybinding, and only allow the M-x form. --- init.el | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index f5b9e25..163d628 100644 --- a/init.el +++ b/init.el @@ -210,15 +210,31 @@ (dolist (sym '(view-hello-file suspend-frame scroll-left - scroll-right)) + scroll-right + comment-set-column + set-fill-column)) (put sym 'disabled t)) ;; And set the disabled function to something better than the default. + ;; Now, I can run any disabled command, but I have to use M-x to do it. (setq disabled-command-function (defun acdw/disabled-command-function (&optional cmd keys) - (unless cmd (setq cmd this-command)) - (unless keys (setq keys (this-command-keys))) - (message "Command `%s' is disabled." cmd)))) + (let ((cmd (or cmd this-command)) + (keys (or keys (this-command-keys)))) + ;; this logic stolen from original `disabled-command-function' + (if (or (eq (aref keys 0) (if (stringp keys) + (aref "\M-x" 0) + ?\M-x)) + (and (>= (length keys) 2) + (eq (aref keys 0) meta-prefix-char) + (eq (aref keys 1) ?x))) + ;; it's been run as an M-x command, we want to do it + (call-interactively cmd) + ;; else, tell the user it's disabled. + (message (substitute-command-keys + (concat "Command `%s' has been disabled. " + "Run with \\[execute-extended-command].")) + cmd)))))) (setup ediff (:option ediff-window-setup-function 'ediff-setup-windows-plain -- cgit 1.4.1-21-gabe81