aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Whitton2024-09-06 11:35:46 +0100
committerSean Whitton2024-09-14 12:16:51 +0100
commitf6417ba91b3fdffc5af43bc4a7ad0b7ed007f442 (patch)
treebc197f0772ba071f2e730828bd5f3330f7cc004f
parent0a6e988b8d2d610d824d84a176fe9c5e86e02a87 (diff)
downloademacs-f6417ba91b3fdffc5af43bc4a7ad0b7ed007f442.tar.gz
emacs-f6417ba91b3fdffc5af43bc4a7ad0b7ed007f442.zip
New commands unix-word-rubout, unix-filename-rubout
* lisp/simple.el (forward-unix-word): New function. (unix-word-rubout, unix-filename-rubout): New commands. * etc/NEWS: Announce the new commands.
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/simple.el57
2 files changed, 63 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index dc633fdeba4..aa6bcf8ab48 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -132,6 +132,12 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch
132fonts, the wrapped text will now be lined up correctly so that it's 132fonts, the wrapped text will now be lined up correctly so that it's
133exactly below the text after the prefix on the first line. 133exactly below the text after the prefix on the first line.
134 134
135---
136** New commands 'unix-word-rubout' and 'unix-filename-rubout'.
137Unix-words are words separated by whitespace regardless of the buffer's
138syntax table. In a Unix terminal or shell, C-w kills by Unix-word.
139The new commands 'unix-word-rubout' and 'unix-filename-rubout' allow
140you to bind keys to operate more similarly to the terminal.
135 141
136* Changes in Specialized Modes and Packages in Emacs 31.1 142* Changes in Specialized Modes and Packages in Emacs 31.1
137 143
diff --git a/lisp/simple.el b/lisp/simple.el
index eedc5768fe2..9b09571b333 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -8896,6 +8896,63 @@ constitute a word."
8896 ;; If we found something nonempty, return it as a string. 8896 ;; If we found something nonempty, return it as a string.
8897 (unless (= start end) 8897 (unless (= start end)
8898 (buffer-substring-no-properties start end))))) 8898 (buffer-substring-no-properties start end)))))
8899
8900(defun forward-unix-word (n &optional delim)
8901 "Move forward N Unix-words.
8902A Unix-word is whitespace-delimited.
8903A negative N means go backwards to the beginning of Unix-words.
8904
8905Unix-words differ from Emacs words in that they are always delimited by
8906whitespace, regardless of the buffer's syntax table. This function
8907emulates how C-w at the Unix terminal or shell identifies words.
8908
8909Optional argument DELIM specifies what characters are considered
8910whitespace. It is a string as might be passed to `skip-chars-forward'.
8911The default is \"\\s\\f\\n\\r\\t\\v\". Do not prefix a `^' character."
8912 (when (string-prefix-p "^" delim)
8913 (error "DELIM argument must not begin with `^'"))
8914 (unless (zerop n)
8915 ;; We do skip over newlines by default because `backward-word' does.
8916 (let* ((delim (or delim "\s\f\n\r\t\v"))
8917 (ndelim (format "^%s" delim))
8918 (start (point))
8919 (fun (if (> n 0)
8920 #'skip-chars-forward
8921 #'skip-chars-backward)))
8922 (dotimes (_ (abs n))
8923 (funcall fun delim)
8924 (funcall fun ndelim))
8925 (constrain-to-field nil start))))
8926
8927(defun unix-word-rubout (arg)
8928 "Kill ARG Unix-words backwards.
8929A Unix-word is whitespace-delimited.
8930Interactively, ARG is the numeric prefix argument, defaulting to 1.
8931A negative ARG means to kill forwards.
8932
8933Unix-words differ from Emacs words in that they are always delimited by
8934whitespace, regardless of the buffer's syntax table.
8935Thus, this command emulates C-w at the Unix terminal or shell.
8936See also this command's nakesake in Info node
8937`(readline)Commands For Killing'."
8938 (interactive "^p")
8939 (let ((start (point)))
8940 (forward-unix-word (- arg))
8941 (kill-region start (point))))
8942
8943(defun unix-filename-rubout (arg)
8944 "Kill ARG Unix-words backwards, also treating slashes as word delimiters.
8945A Unix-word is whitespace-delimited.
8946Interactively, ARG is the numeric prefix argument, defaulting to 1.
8947A negative ARG means to kill forwards.
8948
8949This is like `unix-word-rubout' (which see), but `/' and `\\' are also
8950treated as delimiting words. See this command's namesake in Info node
8951`(readline)Commands For Killing'."
8952 (interactive "^p")
8953 (let ((start (point)))
8954 (forward-unix-word (- arg) "\\\\/\s\f\n\r\t\v")
8955 (kill-region start (point))))
8899 8956
8900(defcustom fill-prefix nil 8957(defcustom fill-prefix nil
8901 "String for filling to insert at front of new line, or nil for none." 8958 "String for filling to insert at front of new line, or nil for none."