diff --git a/README.rst b/README.rst index 1934cd7..48db226 100644 --- a/README.rst +++ b/README.rst @@ -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. @@ -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 +++++ diff --git a/easy-kill.el b/easy-kill.el index 12c2d2c..4a89caa 100644 --- a/easy-kill.el +++ b/easy-kill.el @@ -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 @@ -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) diff --git a/test.el b/test.el index cd1c49f..caa6c4b 100644 --- a/test.el +++ b/test.el @@ -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) {