2021-03-19 23:12:38 +00:00
|
|
|
;;; novice.el --- handling of disabled commands ("novice mode") for Emacs -*- lexical-binding: t -*-
|
1992-05-30 22:12:04 +00:00
|
|
|
|
2023-01-01 10:31:12 +00:00
|
|
|
;; Copyright (C) 1985-1987, 1994, 2001-2023 Free Software Foundation,
|
2013-01-01 09:11:05 +00:00
|
|
|
;; Inc.
|
1992-07-22 04:22:30 +00:00
|
|
|
|
2019-05-25 20:43:06 +00:00
|
|
|
;; Maintainer: emacs-devel@gnu.org
|
1992-07-17 20:24:00 +00:00
|
|
|
;; Keywords: internal, help
|
1992-07-16 21:47:34 +00:00
|
|
|
|
1989-10-31 16:00:07 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 08:06:51 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1989-10-31 16:00:07 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:06:51 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
1989-10-31 16:00:07 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
1989-10-31 16:00:07 +00:00
|
|
|
|
1993-03-22 05:42:35 +00:00
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; This mode provides a hook which is, by default, attached to various
|
|
|
|
;; putatively dangerous commands in a (probably futile) attempt to
|
|
|
|
;; prevent lusers from shooting themselves in the feet.
|
|
|
|
|
1993-03-17 16:56:02 +00:00
|
|
|
;;; Code:
|
1989-10-31 16:00:07 +00:00
|
|
|
|
|
|
|
;; This function is called (by autoloading)
|
|
|
|
;; to handle any disabled command.
|
|
|
|
;; The command is found in this-command
|
|
|
|
;; and the keys are returned by (this-command-keys).
|
|
|
|
|
1991-05-09 21:50:34 +00:00
|
|
|
;;;###autoload
|
2004-08-08 16:05:14 +00:00
|
|
|
(defvar disabled-command-function 'disabled-command-function
|
1996-12-09 04:21:11 +00:00
|
|
|
"Function to call to handle disabled commands.
|
|
|
|
If nil, the feature is disabled, i.e., all commands work normally.")
|
1991-05-13 22:05:10 +00:00
|
|
|
|
2006-09-08 11:59:00 +00:00
|
|
|
;; It is ok here to assume that this-command is a symbol
|
|
|
|
;; because we won't get called otherwise.
|
1991-05-23 00:42:33 +00:00
|
|
|
;;;###autoload
|
2009-11-15 05:12:52 +00:00
|
|
|
(defun disabled-command-function (&optional cmd keys)
|
2021-12-26 15:52:54 +00:00
|
|
|
(let* ((cmd (or cmd this-command))
|
|
|
|
(keys (or keys (this-command-keys)))
|
|
|
|
(help-string
|
|
|
|
(concat
|
|
|
|
(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)))
|
|
|
|
(format "You have invoked the disabled command %s.\n" cmd)
|
|
|
|
(substitute-command-keys
|
|
|
|
(format "You have typed \\`%s', invoking disabled command %s.\n"
|
|
|
|
(key-description keys) cmd)))
|
|
|
|
;; Any special message saying why the command is disabled.
|
|
|
|
(if (stringp (get cmd 'disabled))
|
|
|
|
(get cmd 'disabled)
|
|
|
|
(concat
|
|
|
|
"It is disabled because new users often find it confusing.\n"
|
|
|
|
(substitute-command-keys
|
|
|
|
"Here's the first part of its description:\n\n")
|
|
|
|
;; Keep only the first paragraph of the documentation.
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert (condition-case ()
|
|
|
|
(documentation cmd)
|
|
|
|
(error "<< not documented >>")))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(when (search-forward "\n\n" nil t)
|
|
|
|
(delete-region (match-beginning 0) (point-max)))
|
|
|
|
(indent-rigidly (point-min) (point-max) 3)
|
|
|
|
(buffer-string))))
|
|
|
|
(substitute-command-keys "\n
|
|
|
|
Do you want to use this command anyway?
|
|
|
|
|
|
|
|
You can now type:
|
|
|
|
\\`y' to try it and enable it (no questions if you use it again).
|
|
|
|
\\`n' to cancel--don't try the command, and it remains disabled.
|
|
|
|
\\`SPC' to try the command just this once, but leave it disabled.
|
|
|
|
\\`!' to try it, and enable all disabled commands for this session only.")))
|
|
|
|
(char
|
|
|
|
(car (read-multiple-choice "Use this command?"
|
|
|
|
'((?y "yes")
|
|
|
|
(?n "no")
|
|
|
|
(?! "yes; enable for session")
|
2021-12-27 19:30:41 +00:00
|
|
|
(?\s "(space bar) yes; once"))
|
2021-12-26 15:52:54 +00:00
|
|
|
help-string
|
|
|
|
"*Disabled Command*"))))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 23:13:41 +00:00
|
|
|
(pcase char
|
2021-12-26 15:52:54 +00:00
|
|
|
(?\C-g (setq quit-flag t))
|
|
|
|
(?! (setq disabled-command-function nil))
|
|
|
|
(?y
|
|
|
|
(if (and user-init-file
|
|
|
|
(not (string= "" user-init-file))
|
|
|
|
(y-or-n-p "Enable command for future editing sessions also? "))
|
|
|
|
(enable-command cmd)
|
|
|
|
(put cmd 'disabled nil))))
|
|
|
|
(unless (char-equal char ?n)
|
|
|
|
(call-interactively cmd))))
|
2009-11-15 05:12:52 +00:00
|
|
|
|
|
|
|
(defun en/disable-command (command disable)
|
|
|
|
(unless (commandp command)
|
|
|
|
(error "Invalid command name `%s'" command))
|
|
|
|
(put command 'disabled disable)
|
2002-02-02 12:49:58 +00:00
|
|
|
(let ((init-file user-init-file)
|
|
|
|
(default-init-file
|
|
|
|
(if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
|
2009-11-15 05:12:52 +00:00
|
|
|
(unless init-file
|
2002-02-02 12:49:58 +00:00
|
|
|
(if (or (file-exists-p default-init-file)
|
|
|
|
(and (eq system-type 'windows-nt)
|
|
|
|
(file-exists-p "~/_emacs")))
|
|
|
|
;; Started with -q, i.e. the file containing
|
|
|
|
;; enabled/disabled commands hasn't been read. Saving
|
|
|
|
;; settings there would overwrite other settings.
|
|
|
|
(error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
|
|
|
|
(setq init-file default-init-file)
|
2001-05-27 06:18:28 +00:00
|
|
|
(if (and (not (file-exists-p init-file))
|
|
|
|
(eq system-type 'windows-nt)
|
|
|
|
(file-exists-p "~/_emacs"))
|
|
|
|
(setq init-file "~/_emacs")))
|
* x-dnd.el (x-dnd-maybe-call-test-function):
* window.el (split-window-vertically):
* whitespace.el (whitespace-help-on):
* vc-rcs.el (vc-rcs-consult-headers):
* userlock.el (ask-user-about-lock-help)
(ask-user-about-supersession-help):
* type-break.el (type-break-force-mode-line-update):
* time-stamp.el (time-stamp-conv-warn):
* terminal.el (te-set-output-log, te-more-break, te-filter)
(te-sentinel,terminal-emulator):
* term.el (make-term, term-exec, term-sentinel, term-read-input-ring)
(term-write-input-ring, term-check-source, term-start-output-log):
(term-display-buffer-line, term-dynamic-list-completions):
(term-ansi-make-term, serial-term):
* subr.el (selective-display):
* strokes.el (strokes-xpm-to-compressed-string, strokes-decode-buffer)
(strokes-encode-buffer, strokes-xpm-for-compressed-string):
* speedbar.el (speedbar-buffers-tail-notes, speedbar-buffers-item-info)
(speedbar-reconfigure-keymaps, speedbar-add-localized-speedbar-support)
(speedbar-remove-localized-speedbar-support)
(speedbar-set-mode-line-format, speedbar-create-tag-hierarchy)
(speedbar-update-special-contents, speedbar-buffer-buttons-engine)
(speedbar-buffers-line-directory):
* simple.el (shell-command-on-region, append-to-buffer)
(prepend-to-buffer):
* shadowfile.el (shadow-save-todo-file):
* scroll-bar.el (scroll-bar-set-window-start, scroll-bar-drag-1)
(scroll-bar-maybe-set-window-start):
* sb-image.el (speedbar-image-dump):
* saveplace.el (save-place-alist-to-file, save-places-to-alist)
(load-save-place-alist-from-file):
* ps-samp.el (ps-print-message-from-summary):
* ps-print.el (ps-flush-output, ps-insert-file, ps-get-boundingbox)
(ps-background-image, ps-begin-job, ps-do-despool):
* ps-bdf.el (bdf-find-file, bdf-read-font-info):
* printing.el (pr-interface, pr-ps-file-print, pr-find-buffer-visiting)
(pr-ps-message-from-summary, pr-lpr-message-from-summary):
(pr-call-process, pr-file-list, pr-interface-save):
* novice.el (disabled-command-function)
(enable-command, disable-command):
* mouse.el (mouse-buffer-menu-alist):
* mouse-copy.el (mouse-kill-preserving-secondary):
* macros.el (kbd-macro-query):
* ledit.el (ledit-go-to-lisp, ledit-go-to-liszt):
* informat.el (batch-info-validate):
* ido.el (ido-copy-current-word, ido-initiate-auto-merge):
* hippie-exp.el (try-expand-dabbrev-visible):
* help-mode.el (help-make-xrefs):
* help-fns.el (describe-variable):
* generic-x.el (bat-generic-mode-run-as-comint):
* finder.el (finder-mouse-select):
* find-dired.el (find-dired-sentinel):
* filesets.el (filesets-file-close):
* files.el (list-directory):
* faces.el (list-faces-display, describe-face):
* facemenu.el (list-colors-display):
* ezimage.el (ezimage-image-association-dump, ezimage-image-dump):
* epg.el (epg--process-filter, epg-cancel):
* epa.el (epa--marked-keys, epa--select-keys, epa-display-info)
(epa--read-signature-type):
* emerge.el (emerge-copy-as-kill-A, emerge-copy-as-kill-B)
(emerge-file-names):
* ehelp.el (electric-helpify):
* ediff.el (ediff-regions-wordwise, ediff-regions-linewise):
* ediff-vers.el (rcs-ediff-view-revision):
* ediff-util.el (ediff-setup):
* ediff-mult.el (ediff-append-custom-diff):
* ediff-diff.el (ediff-exec-process, ediff-process-sentinel)
(ediff-wordify):
* echistory.el (Electric-command-history-redo-expression):
* dos-w32.el (find-file-not-found-set-buffer-file-coding-system):
* disp-table.el (describe-display-table):
* dired.el (dired-find-buffer-nocreate):
* dired-aux.el (dired-rename-subdir, dired-dwim-target-directory):
* dabbrev.el (dabbrev--same-major-mode-p):
* chistory.el (list-command-history):
* apropos.el (apropos-documentation):
* allout.el (allout-obtain-passphrase):
(allout-copy-exposed-to-buffer):
(allout-verify-passphrase): Use with-current-buffer.
2009-11-13 22:19:45 +00:00
|
|
|
(with-current-buffer (find-file-noselect
|
|
|
|
(substitute-in-file-name init-file))
|
2001-05-27 06:18:28 +00:00
|
|
|
(goto-char (point-min))
|
|
|
|
(if (search-forward (concat "(put '" (symbol-name command) " ") nil t)
|
|
|
|
(delete-region
|
|
|
|
(progn (beginning-of-line) (point))
|
|
|
|
(progn (forward-line 1) (point))))
|
|
|
|
;; Explicitly enable, in case this command is disabled by default
|
|
|
|
;; or in case the code we deleted was actually a comment.
|
|
|
|
(goto-char (point-max))
|
2009-11-15 05:12:52 +00:00
|
|
|
(unless (bolp) (newline))
|
|
|
|
(insert "(put '" (symbol-name command) " 'disabled "
|
|
|
|
(symbol-name disable) ")\n")
|
2001-05-27 06:18:28 +00:00
|
|
|
(save-buffer))))
|
1989-10-31 16:00:07 +00:00
|
|
|
|
2009-11-15 05:12:52 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defun enable-command (command)
|
|
|
|
"Allow COMMAND to be executed without special confirmation from now on.
|
|
|
|
COMMAND must be a symbol.
|
|
|
|
This command alters the user's .emacs file so that this will apply
|
|
|
|
to future sessions."
|
|
|
|
(interactive "CEnable command: ")
|
|
|
|
(en/disable-command command nil))
|
|
|
|
|
1991-05-09 21:50:34 +00:00
|
|
|
;;;###autoload
|
1989-10-31 16:00:07 +00:00
|
|
|
(defun disable-command (command)
|
|
|
|
"Require special confirmation to execute COMMAND from now on.
|
2004-07-31 15:43:26 +00:00
|
|
|
COMMAND must be a symbol.
|
2012-09-17 05:41:04 +00:00
|
|
|
This command alters your init file so that this choice applies to
|
|
|
|
future sessions."
|
1989-10-31 16:00:07 +00:00
|
|
|
(interactive "CDisable command: ")
|
2009-11-15 05:12:52 +00:00
|
|
|
(en/disable-command command t))
|
1989-10-31 16:00:07 +00:00
|
|
|
|
1997-06-22 18:57:55 +00:00
|
|
|
(provide 'novice)
|
|
|
|
|
1992-05-30 22:12:04 +00:00
|
|
|
;;; novice.el ends here
|