Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new targets: buffer, buffer-before-point and buffer-after point. #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 3 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
30 changes: 29 additions & 1 deletion easy-kill.el
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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 @@ -744,6 +747,31 @@ inspected."
(setf (easy-kill-get thing) 'sexp)))
(_ (easy-kill-thing 'sexp n t))))

(defun easy-kill-on-buffer (n)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some docstrings for the new functions. I know they are simple, but still.

(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 @@ -214,6 +214,37 @@
(easy-kill-thing 'list)
(should (string= "dummy" (easy-kill-candidate))))))

(ert-deftest test-easy-kill-on-buffer ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd split this test into 3 tests. I think this will make it more readable and will show better what exactly is being tested.

(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