diff --git a/README.org b/README.org index d8438c8..ab4fc4d 100644 --- a/README.org +++ b/README.org @@ -935,6 +935,62 @@ option to run different commands on those selections. * Editing +** [[https://www.emacswiki.org/emacs/DisabledCommands][Enable disabled commands and inform]] +:PROPERTIES: +:CUSTOM_ID: sec:enable-disabled-commands +:END: + +Execute src_emacs-lisp[:exports code]{(find-library "novice")} to see how +Emacs prevents new users from shooting themselves in the feet. + +#+begin_src emacs-lisp + (setq disabled-command-function + (defun my-enable-this-command (&rest _args) + "Called when a disabled command is executed. + Enable it and re-execute it." + (put this-command 'disabled nil) + (message "You typed %s. %s was disabled until now." + (key-description (this-command-keys)) this-command) + (sit-for 0) + (call-interactively this-command))) +#+end_src + + +** [[info:emacs#Narrowing][Narrowing]] +:PROPERTIES: +:CUSTOM_ID: sec:narrowing +:END: + +[[https://endlessparentheses.com/emacs-narrow-or-widen-dwim.html][Emacs narrow-or-widen-dwim]] + +#+begin_src emacs-lisp + (defun narrow-or-widen-dwim (p) + "Widen if buffer is narrowed, narrow-dwim otherwise. + Dwim means: region, org-src-block, org-subtree, or defun, + whichever applies first. Narrowing to org-src-block actually + calls `org-edit-src-code'. + With prefix P, don't widen, just narrow even if buffer is + already narrowed." + (interactive "P") + (declare (interactive-only)) + (cond ((and (buffer-narrowed-p) (not p)) (widen)) + ((and (bound-and-true-p org-src-mode) (not p)) + (org-edit-src-exit)) + ((region-active-p) + (narrow-to-region (region-beginning) (region-end))) + ((derived-mode-p 'org-mode) + (or (ignore-errors (org-edit-src-code)) + (ignore-errors (org-narrow-to-block)) + (org-narrow-to-subtree))) + ((derived-mode-p 'latex-mode) + (LaTeX-narrow-to-environment)) + ((derived-mode-p 'tex-mode) + (TeX-narrow-to-group)) + (t (narrow-to-defun)))) + + (define-key ctl-x-map (kbd "C-n") #'narrow-or-widen-dwim) +#+end_src + ** Synchronal multiple-region editing #+attr_latex: :options bgcolor=LightGoldenrodYellow