Skip to content

Commit

Permalink
Add new targets: buffer, buffer-before-point and buffer-after point.
Browse files Browse the repository at this point in the history
  • Loading branch information
knu committed Jul 2, 2014
1 parent 5226660 commit fbae6bd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ active region, url, email and finally current line (See
#. ``M-w d``: save defun at point
#. ``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
30 changes: 29 additions & 1 deletion easy-kill.el
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
(?f filename "\n")
(?d defun "\n\n")
(?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 @@ -726,6 +729,31 @@ inspected."
(setf (easy-kill-get thing) 'sexp)))
(_ (easy-kill-thing 'sexp n t))))

(defun easy-kill-on-buffer (n)
(easy-kill-adjust-candidate 'buffer (point-min) (point-max)))

(defun easy-kill-on-buffer-after-point (n)
(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)
(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
31 changes: 31 additions & 0 deletions test.el
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,37 @@
(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"))

(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"))

(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

0 comments on commit fbae6bd

Please sign in to comment.