diff --git a/CHANGELOG.develop b/CHANGELOG.develop index bb9a589db..5c10a15ca 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -521,10 +521,12 @@ Other: terminal mode, but no longer in GUI mode. (emacs18) *** Core changes - Improvements: - - Provide keybindings for using narrow with an indirect buffer (to function - definition, ~SPC n F~; to page, ~SPC n P~; to region, ~SPC n R~) for when you - want narrowing multiple times in the same base buffer (thanks to Keith - Pinson and duianto) + - Provide keybindings for using narrow with an indirect buffer for when you + want narrowing multiple times in the same base buffer: + - ~SPC n F~ for narrow to function + - ~SPC n P~ for narrow to page + - ~SPC n R~ for narrow to region + (thanks to Keith Pinson and duianto) - Make =describe-text-properties= available in the help -> describe menu via ~SPC h d t~ (thanks to Keith Pinson) - Bind ~SPC c n~ to ~:cn~ / ~next-error~ and ~SPC c N~ to ~:cN~ / ~previous-error~ diff --git a/layers/+spacemacs/spacemacs-defaults/funcs.el b/layers/+spacemacs/spacemacs-defaults/funcs.el index 63aae780b..f1593f1ad 100644 --- a/layers/+spacemacs/spacemacs-defaults/funcs.el +++ b/layers/+spacemacs/spacemacs-defaults/funcs.el @@ -1728,26 +1728,36 @@ Decision is based on `dotspacemacs-line-numbers'." ;; narrow region +(defun spacemacs/clone-indirect-buffer-de-activate-mark () + "This is a workaround for the evil visual state error message like: +Error in post-command-hook (evil-visual-post-command): +(error \"Marker points into wrong buffer\" #>)" + (let ((region-was-active (region-active-p))) + (when region-was-active (deactivate-mark)) + (call-interactively 'clone-indirect-buffer) + (when region-was-active (activate-mark)))) + +(defun spacemacs/narrow-to-indirect-buffer (f x) + "Use the function `f' to narrow within an indirect buffer, except where the +starting buffer is in a state (such as visual block mode) that would cause this +to work incorrectly. `x' is the string name of the entity being narrowed to." + ;; There may be a way to get visual block mode working similar to the + ;; workaround we did for visual line mode; this usecase however seems like an + ;; edgecase at best, so let's patch it if we find out it's needed; otherwise + ;; let's not hold up the base functionality anymore. + (when (not (and (eq evil-state 'visual) (eq evil-visual-selection 'block))) + (spacemacs/clone-indirect-buffer-de-activate-mark) + (call-interactively f) + (message (format "%s narrowed to an indirect buffer" x)))) + (defun spacemacs/narrow-to-defun-indirect-buffer () (interactive) - (deactivate-mark) - (call-interactively 'clone-indirect-buffer) - (activate-mark) - (call-interactively 'narrow-to-defun) - (message "Function narrowed to an indirect buffer")) + (spacemacs/narrow-to-indirect-buffer 'narrow-to-defun "Function")) (defun spacemacs/narrow-to-page-indirect-buffer () (interactive) - (deactivate-mark) - (call-interactively 'clone-indirect-buffer) - (activate-mark) - (call-interactively 'narrow-to-page) - (message "Page narrowed to an indirect buffer")) + (spacemacs/narrow-to-indirect-buffer 'narrow-to-page "Page")) (defun spacemacs/narrow-to-region-indirect-buffer () (interactive) - (deactivate-mark) - (call-interactively 'clone-indirect-buffer) - (activate-mark) - (call-interactively 'narrow-to-region) - (message "Region narrowed to an indirect buffer")) + (spacemacs/narrow-to-indirect-buffer 'narrow-to-region "Region"))