Last active
May 19, 2018 23:28
-
-
Save mwfogleman/95cc60c87a9323876c6c to your computer and use it in GitHub Desktop.
Emacs: narrow-or-widen-dwim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun narrow-or-widen-dwim () | |
"If the buffer is narrowed, it widens. Otherwise, it narrows to region, or Org subtree." | |
(interactive) | |
(cond ((buffer-narrowed-p) (widen)) | |
((region-active-p) (narrow-to-region (region-beginning) (region-end))) | |
((equal major-mode 'org-mode) (org-narrow-to-subtree)) | |
(t (error "Please select a region to narrow to")))) | |
;; I bind this key to C-c n, using the bind-key function that comes with use-package. | |
(bind-key "C-c n" 'narrow-or-widen-dwim) | |
;; I also bind it to C-x t n, using Artur Malabarba's toggle map idea: | |
;; http:://www.endlessparentheses.com/the-toggle-map-and-wizardry.html | |
(bind-key "n" 'narrow-or-widen-dwim toggle-map) |
Yes, and yes!
Nice. What I did though was add a speed command to org:
("n" . org-narrow-to-subtree)
but I still type M-x widen to undo it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is nice. Did you write this? If so, could I mention it on the blog?