emacs/var/elfeed/db/data/73/73f0e9eb94e77aae587342cb4a2d986643cbdfa5
2022-01-03 12:49:32 -06:00

1 line
2.5 KiB
Plaintext

<!-- SC_OFF --><div class="md"><p>I am annoyed that when I <code>C-g</code> out of my expand-region session my cursor does not return to its original location.</p> <p>In trying to resolve this annoyance I found that expand-region comes with a variable <code>er/save-mode-excursion</code> that is described as:</p> <blockquote> <p>A function to save excursion state while expanding</p> </blockquote> <p>I set this variable to <code>(lambda (&amp;rest body) () (save-excursion body))</code> and I found that this does not suit my needs for the following reasons.</p> <ul> <li>This variable does not seem to effect any <code>er/mark-</code> commands outside of <code>er/expand-region</code>. For example if I do <code>er/mark-defun</code> and then hit <code>C-g</code> my cursor position is not returned.</li> <li>I often use a key-chord bound to <code>(lambda () (interactive) (execute-kbd-macro (read-kbd-macro &quot;\C-g&quot;)))</code>. When I use this key-chord instead of actually hitting C-g my cursor position is not returned. I do not understand why this is.</li> </ul> <p>Next I tried taking advantage of the <code>deactivate-mark-hook</code> to programatically hit <code>C-u C-SPC</code>.</p> <pre><code>(add-hook &#39;deactivate-mark-hook #&#39;(lambda () (let ((current-prefix-arg 4)) (call-interactively &#39;set-mark-command)))) </code></pre> <p>This works great for my non expand-region region endeavours but when I try to use any <code>er/</code> commands I get unpredictable behavior. I believe the problem is that expand-region resets the mark multiple times and therefore <code>deactivate-mark-hook</code> is called multiple times.</p> <p>In regards to the <code>er/mark-</code> functions I tried to wrap them all up in new functions that wrap a <code>save-excursion</code> but the behavior is not what I expected. For example if I try this on <code>er/mark-defun</code> then the marked region becomes from the current point to the end of the defun instead of marking the entire defun.</p> <p>My next idea is to make my own <code>expand-region-minor-mode</code> where I can probably solve this problem. Before I do this though I want to know if there are already existing solutions.</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/thirtySeven73"> /u/thirtySeven73 </a> <br/> <span><a href="https://www.reddit.com/r/emacs/comments/qzu4pd/how_can_i_saveexcursion_with_expandregion/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/emacs/comments/qzu4pd/how_can_i_saveexcursion_with_expandregion/">[comments]</a></span>