mirror of
https://codeberg.org/scip/dot-emacs.git
synced 2025-12-17 20:40:58 +01:00
added global narrowing function, disable narrow prefix in orgmode
This commit is contained in:
@@ -21,6 +21,39 @@
|
||||
|
||||
(add-hook 'post-command-hook 'tvd-narrowed-fringe-status)
|
||||
|
||||
;; via https://endlessparentheses.com/emacs-narrow-or-widen-dwim.html
|
||||
;; pure genius, never ever have to think about how to widen
|
||||
(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))
|
||||
((region-active-p)
|
||||
(narrow-to-region (region-beginning)
|
||||
(region-end)))
|
||||
((derived-mode-p 'org-mode)
|
||||
;; `org-edit-src-code' is not a real narrowing
|
||||
;; command. Remove this first conditional if
|
||||
;; you don't want it.
|
||||
(cond ((ignore-errors (org-edit-src-code) t)
|
||||
(delete-other-windows))
|
||||
((ignore-errors (org-narrow-to-block) t))
|
||||
(t (org-narrow-to-subtree))))
|
||||
((derived-mode-p 'latex-mode)
|
||||
(LaTeX-narrow-to-environment))
|
||||
(t (narrow-to-defun))))
|
||||
|
||||
;; This line actually replaces Emacs' entire narrowing
|
||||
;; keymap, that's how much I like this command. Only
|
||||
;; copy it if that's what you want.
|
||||
(define-key ctl-x-map "n" #'narrow-or-widen-dwim)
|
||||
|
||||
|
||||
(provide 'init-narrow)
|
||||
;;; init-narrow.el ends here
|
||||
|
||||
Reference in New Issue
Block a user