diff options
| author | Sean Whitton | 2024-09-06 11:35:46 +0100 |
|---|---|---|
| committer | Sean Whitton | 2024-09-14 12:16:51 +0100 |
| commit | f6417ba91b3fdffc5af43bc4a7ad0b7ed007f442 (patch) | |
| tree | bc197f0772ba071f2e730828bd5f3330f7cc004f | |
| parent | 0a6e988b8d2d610d824d84a176fe9c5e86e02a87 (diff) | |
| download | emacs-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/NEWS | 6 | ||||
| -rw-r--r-- | lisp/simple.el | 57 |
2 files changed, 63 insertions, 0 deletions
| @@ -132,6 +132,12 @@ When using 'visual-wrap-prefix-mode' in buffers with variable-pitch | |||
| 132 | fonts, the wrapped text will now be lined up correctly so that it's | 132 | fonts, the wrapped text will now be lined up correctly so that it's |
| 133 | exactly below the text after the prefix on the first line. | 133 | exactly below the text after the prefix on the first line. |
| 134 | 134 | ||
| 135 | --- | ||
| 136 | ** New commands 'unix-word-rubout' and 'unix-filename-rubout'. | ||
| 137 | Unix-words are words separated by whitespace regardless of the buffer's | ||
| 138 | syntax table. In a Unix terminal or shell, C-w kills by Unix-word. | ||
| 139 | The new commands 'unix-word-rubout' and 'unix-filename-rubout' allow | ||
| 140 | you 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. | ||
| 8902 | A Unix-word is whitespace-delimited. | ||
| 8903 | A negative N means go backwards to the beginning of Unix-words. | ||
| 8904 | |||
| 8905 | Unix-words differ from Emacs words in that they are always delimited by | ||
| 8906 | whitespace, regardless of the buffer's syntax table. This function | ||
| 8907 | emulates how C-w at the Unix terminal or shell identifies words. | ||
| 8908 | |||
| 8909 | Optional argument DELIM specifies what characters are considered | ||
| 8910 | whitespace. It is a string as might be passed to `skip-chars-forward'. | ||
| 8911 | The 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. | ||
| 8929 | A Unix-word is whitespace-delimited. | ||
| 8930 | Interactively, ARG is the numeric prefix argument, defaulting to 1. | ||
| 8931 | A negative ARG means to kill forwards. | ||
| 8932 | |||
| 8933 | Unix-words differ from Emacs words in that they are always delimited by | ||
| 8934 | whitespace, regardless of the buffer's syntax table. | ||
| 8935 | Thus, this command emulates C-w at the Unix terminal or shell. | ||
| 8936 | See 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. | ||
| 8945 | A Unix-word is whitespace-delimited. | ||
| 8946 | Interactively, ARG is the numeric prefix argument, defaulting to 1. | ||
| 8947 | A negative ARG means to kill forwards. | ||
| 8948 | |||
| 8949 | This is like `unix-word-rubout' (which see), but `/' and `\\' are also | ||
| 8950 | treated 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." |