mirror of
https://codeberg.org/scip/dot-emacs.git
synced 2025-12-17 04:20:57 +01:00
fixed narrowing function by adding a custom defun narrower
This commit is contained in:
@@ -21,6 +21,26 @@
|
|||||||
|
|
||||||
(add-hook 'post-command-hook 'tvd-narrowed-fringe-status)
|
(add-hook 'post-command-hook 'tvd-narrowed-fringe-status)
|
||||||
|
|
||||||
|
;; I have to write my own version of narrow-to-defun because
|
||||||
|
;; beginning+end-of-defun doesn't find a function which is defined
|
||||||
|
;; inside a use-package block
|
||||||
|
(defun tvd-narrow-to-defun()
|
||||||
|
"Same as 'narrow-to-defun but also considers indented defuns.
|
||||||
|
|
||||||
|
It uses smart-parens to find the defun end. Must be inside a (defun) form."
|
||||||
|
(interactive)
|
||||||
|
(let ((here (point))
|
||||||
|
(beg 0)
|
||||||
|
(end 0))
|
||||||
|
(save-excursion
|
||||||
|
(search-backward "(defun")
|
||||||
|
(setq beg (point))
|
||||||
|
(forward-char)
|
||||||
|
(sp-end-of-sexp)
|
||||||
|
(forward-char)
|
||||||
|
(setq end (point)))
|
||||||
|
(narrow-to-region beg end)))
|
||||||
|
|
||||||
;; via https://endlessparentheses.com/emacs-narrow-or-widen-dwim.html
|
;; via https://endlessparentheses.com/emacs-narrow-or-widen-dwim.html
|
||||||
;; pure genius, never ever have to think about how to widen
|
;; pure genius, never ever have to think about how to widen
|
||||||
(defun narrow-or-widen-dwim (p)
|
(defun narrow-or-widen-dwim (p)
|
||||||
@@ -47,7 +67,7 @@ is already narrowed."
|
|||||||
(t (org-narrow-to-subtree))))
|
(t (org-narrow-to-subtree))))
|
||||||
((derived-mode-p 'latex-mode)
|
((derived-mode-p 'latex-mode)
|
||||||
(LaTeX-narrow-to-environment))
|
(LaTeX-narrow-to-environment))
|
||||||
(t (narrow-to-defun))))
|
(t (tvd-narrow-to-defun))))
|
||||||
|
|
||||||
;; This line actually replaces Emacs' entire narrowing
|
;; This line actually replaces Emacs' entire narrowing
|
||||||
;; keymap, that's how much I like this command. Only
|
;; keymap, that's how much I like this command. Only
|
||||||
|
|||||||
Reference in New Issue
Block a user