[core] fix visual modes for narrow to indirect buffer

* Apply @duianto's fix to only activate visual selection it if it was active
  previous to the creation of the indirect buffer
* Block use of visual block mode because of continuing problems in that mode,
  and its questionable usefulness in this case
* Extract commonalities out of the narrowing functions
* Make the new keybindings into a list in the changelog for readability, per
  @duianto
This commit is contained in:
Keith Pinson 2020-10-28 10:06:48 -04:00 committed by duianto
parent 155490afaf
commit 82974b454e
2 changed files with 31 additions and 19 deletions

View File

@ -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~

View File

@ -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\" #<marker at 27875 in .spacemacs<2>>)"
(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"))