Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ active region, url, email and finally current line (See
#. ``M-w D``: save current defun name
#. ``M-w f``: save file at point
#. ``M-w b``: save ``buffer-file-name`` or ``default-directory``.
#. ``M-w a``: save the whole buffer content
#. ``M-w <``: save the buffer content before point
#. ``M-w >``: save the buffer content after point
``-`` changes the kill to the directory name, ``+`` to full name
and ``0`` to basename.

Expand Down Expand Up @@ -97,6 +100,13 @@ convention, or by defining new functions named like
NEWS
~~~~

Unreleased
++++++++++

#. New things ``buffer``, ``buffer-before-point`` and
``buffer-after-point`` for selecting the whole buffer or parts
of it around the point.

0.9.5
+++++

Expand Down
37 changes: 36 additions & 1 deletion easy-kill.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
(?d defun "\n\n")
(?D defun-name " ")
(?e line "\n")
(?b buffer-file-name))
(?b buffer-file-name)
(?a buffer)
(?< buffer-before-point)
(?> buffer-after-point))
"A list of (CHAR THING APPEND).
CHAR is used immediately following `easy-kill' to select THING.
APPEND is optional and if non-nil specifies the separator (a
Expand Down Expand Up @@ -728,6 +731,38 @@ inspected."
(setf (easy-kill-get thing) 'sexp)))
(_ (easy-kill-thing 'sexp n t))))

(defun easy-kill-on-buffer (_n)
"Select the whole buffer."
(easy-kill-adjust-candidate 'buffer (point-min) (point-max)))

(defun easy-kill-on-buffer-after-point (n)
"Select buffer contents after point.
If N is +, extend to the beginning of the current line.
If N is -, shrink to the beginning of the next line."
(easy-kill-adjust-candidate 'buffer-after-point
(pcase n
(`+
(point-at-bol))
(`-
(point-at-bol 2))
(_
(point)))
(point-max)))

(defun easy-kill-on-buffer-before-point (n)
"Select buffer contents before point.
If N is +, extend to the end of the current line.
If N is -, shrink to the beginning of the current line."
(easy-kill-adjust-candidate 'buffer-before-point
(point-min)
(pcase n
(`+
(point-at-bol 2))
(`-
(point-at-bol))
(_
(point)))))

;;; nxml support for list-wise +/-

(defvar nxml-sexp-element-flag)
Expand Down
45 changes: 45 additions & 0 deletions test.el
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,51 @@
(easy-kill-thing 'list)
(should (string= "dummy" (easy-kill-candidate))))))

(ert-deftest test-easy-kill-on-buffer ()
(with-temp-buffer
(insert "line 1\n")
(insert "line 2\n")
(insert "line 3\n")
(forward-line -2)
(forward-word)
(easy-kill-on-buffer 1)
(easy-kill-save-candidate)
(should (string= (car kill-ring) "line 1\nline 2\nline 3\n"))))

(ert-deftest test-easy-kill-on-buffer-before-point ()
(with-temp-buffer
(insert "line 1\n")
(insert "line 2\n")
(insert "line 3\n")
(forward-line -2)
(forward-word)
(easy-kill-on-buffer-before-point 1)
(easy-kill-save-candidate)
(should (string= (car kill-ring) "line 1\nline"))
(easy-kill-on-buffer-before-point '-)
(easy-kill-save-candidate)
(should (string= (car kill-ring) "line 1\n"))
(easy-kill-on-buffer-before-point '+)
(easy-kill-save-candidate)
(should (string= (car kill-ring) "line 1\nline 2\n"))))

(ert-deftest test-easy-kill-on-buffer-after-point ()
(with-temp-buffer
(insert "line 1\n")
(insert "line 2\n")
(insert "line 3\n")
(forward-line -2)
(forward-word)
(easy-kill-on-buffer-after-point 1)
(easy-kill-save-candidate)
(should (string= (car kill-ring) " 2\nline 3\n"))
(easy-kill-on-buffer-after-point '-)
(easy-kill-save-candidate)
(should (string= (car kill-ring) "line 3\n"))
(easy-kill-on-buffer-after-point '+)
(easy-kill-save-candidate)
(should (string= (car kill-ring) "line 2\nline 3\n"))))

(ert-deftest test-js2-mode ()
:expected-result :failed
(let ((js "function View(name, options) {
Expand Down