added global narrowing function, disable narrow prefix in orgmode

This commit is contained in:
2023-06-15 18:38:18 +02:00
parent 976452038f
commit fcd9f3e2f2
2 changed files with 36 additions and 0 deletions

View File

@@ -21,6 +21,39 @@
(add-hook 'post-command-hook 'tvd-narrowed-fringe-status) (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) (provide 'init-narrow)
;;; init-narrow.el ends here ;;; init-narrow.el ends here

View File

@@ -164,6 +164,9 @@ down and unfold it, otherwise jump paragraph as usual."
; run presenter, org-present must be installed and loadedwhite ; run presenter, org-present must be installed and loadedwhite
(local-set-key (kbd "C-p") 'org-present) (local-set-key (kbd "C-p") 'org-present)
;; we need to remove the narrowing prefix, because we use 'narrow-or-widen-dwim globally
(define-key org-mode-map (kbd "C-x n") nil)
; todo colors ; todo colors
(setq org-todo-keyword-faces '( (setq org-todo-keyword-faces '(
("TODO" . (:foreground "deepskyblue" :weight bold)) ("TODO" . (:foreground "deepskyblue" :weight bold))