Last active
February 11, 2023 02:09
-
-
Save ae-s/ff69497ac3c4c2f65e53d269a3fc30f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
; this defun ripped from http://www.emacswiki.org/emacs/narrow-indirect.el | |
(defun narrow-to-region-indirect-other-window (start end here text) | |
"`narrow-to-region' in a cloned indirect buffer in the other window. | |
The indirect buffer is named the same as the current buffer, | |
except it is suffixed by `:text'. | |
Non-interactively: | |
START and END are the region beginning and end. | |
HERE is where to place the cursor, relative to START. | |
TEXT is prefixed by `:' and appended to the | |
original buffer name. | |
See `clone-indirect-buffer'." | |
(interactive | |
(list (region-beginning) (region-end) (point) (and current-prefix-arg (read-string "Buffer name: ")) nil 'MSGP)) | |
(if (and (= start end) msgp) | |
(message "Region is empty") | |
(deactivate-mark) | |
(let* ((buf (concat (buffer-name) ":" text)) | |
(buf (clone-indirect-buffer buf nil))) | |
(with-current-buffer buf (narrow-to-region start end) (goto-char here)) | |
))) | |
;; not quite there yet, but | |
(defun split-this-defun () | |
(interactive) | |
(save-excursion | |
(let ((start (point))) | |
(end-of-defun) | |
(previous-line 1) | |
(let ((name (c-defun-name))) | |
(end-of-defun) | |
(next-line 1) | |
(narrow-to-region-indirect-other-window start (point) start name))))) | |
(defun split-buffer-by-defuns () | |
(interactive) | |
(save-excursion | |
(let ((parent-point (point))) | |
(goto-char (point-min)) | |
(while (not (= (point) (point-max))) | |
(let ((start (point))) | |
(end-of-defun) | |
(previous-line 1) | |
(let ((name (c-defun-name))) | |
(end-of-defun) | |
(next-line 1) | |
(narrow-to-region-indirect-other-window start (point) parent-point name))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment