Stefan Kangas <stefankan...@gmail.com> writes:
> Eli Zaretskii <e...@gnu.org> writes: > >>> From: Philip Kaludercic <phil...@posteo.net> >>> Cc: Sean Whitton <spwhit...@spwhitton.name>, j...@linkov.net, >>> r...@gnu.org, >>> 69...@debbugs.gnu.org >>> Date: Sun, 01 Sep 2024 20:06:00 +0000 >>> >>> Ping. I am not sure how to proceed on this patch. IIRC the issue was >>> that the notion of a word differs in Emacs and in Bash. I am still in >>> favour of utilising Emacs's definition, as it remains more useful >>> for some given major mode and the fact that it is easier to implement. >> >> Or you could make the defcustom a tristate, and implement both >> behaviors... >> >> As for how to proceed: Stefan and Andrea, do you have an opinion on >> this? > > Binding C-w to backward-kill-word, or some version thereof, is an old > Emacs power user trick that has been recommended in many places over the > years. See, for example: > https://sites.google.com/site/steveyegge2/effective-emacs#h.p_ID_193 > https://emacs-fu.blogspot.com/2009/11/copying-lines-without-selecting-them.html > > So I think this command would be a good addition. Making the word > boundary behaviour into a tristate option sounds like a reasonable way > forward, which should make everyone happy and let people experiment with > what works best for them. How about this suggestion: We add a generic kill-region-or-word command, and a user option for a function (set to either `backward-kill-word' or Sean's `unix-word-rubout'). I can prepare a patch with the simpler version, and then Sean can add his behaviour in a second patch so that the attribution remains correct. Sean Whitton <spwhit...@spwhitton.name> writes: > Hello, > > On Mon 02 Sep 2024 at 11:30am -07, Stefan Kangas wrote: > >> Binding C-w to backward-kill-word, or some version thereof, is an old >> Emacs power user trick that has been recommended in many places over the >> years. See, for example: >> https://sites.google.com/site/steveyegge2/effective-emacs#h.p_ID_193 >> https://emacs-fu.blogspot.com/2009/11/copying-lines-without-selecting-them.html >> >> So I think this command would be a good addition. Making the word >> boundary behaviour into a tristate option sounds like a reasonable way >> forward, which should make everyone happy and let people experiment with >> what works best for them. > > For reference purposes while implementing the tristate, here is my > implementation of the Unix behaviour from my init. > Should be helpful, though there is lots of room for improvement :) > > (defun spw/unix-word-rubout (arg &optional pos neg) > (interactive "p") > ;; Do skip over \n because `backward-kill-word' does. > (unless pos (setq pos "[:space:]\n")) > (unless neg (setq neg "^[:space:]\n")) > (undo-boundary) > (let ((start (point))) > ;; Go only backwards. > (dotimes (_ (abs arg)) > (skip-chars-backward pos) > (skip-chars-backward neg)) > ;; Skip forward over any read-only text (e.g. an Eshell or comint > prompt). > (when-let ((beg (and (get-char-property (point) 'read-only) > (next-single-char-property-change > (point) 'read-only nil start)))) > (goto-char beg)) > (kill-region start (point)))) FWIW I don't have any suggestions on how to improve the function either. I wonder if it would make sense to have a minor mode like subword-mode that would enforce a understanding of words like implemented here. -- Philip Kaludercic on peregrine