re-wrote viking--kill-space, which now does not delete the last newline between two paragraphs, which is much more natural

This commit is contained in:
git@daemon.de
2016-05-19 14:32:55 +02:00
parent beac22d87f
commit f32ca58974

View File

@@ -19,7 +19,7 @@
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
;; USA ;; USA
;; Version: 0.03 ;; Version: 0.04
;; Author: T.v.Dein <tlinden@cpan.org> ;; Author: T.v.Dein <tlinden@cpan.org>
;; Keywords: kill delete ;; Keywords: kill delete
;; URL: https://github.com/tlinden/viking-mode ;; URL: https://github.com/tlinden/viking-mode
@@ -166,7 +166,7 @@
;;; Code: ;;; Code:
;;;; Consts ;;;; Consts
(defconst viking-mode-version "0.03" "Viking Mode version.") (defconst viking-mode-version "0.04" "Viking Mode version.")
(defgroup viking-mode nil (defgroup viking-mode nil
"Kill first, ask later - an emacs mode for killing things quickly" "Kill first, ask later - an emacs mode for killing things quickly"
@@ -291,17 +291,29 @@ should be a point-moving function."
(viking--kill-region beg end) (viking--kill-region beg end)
(message "word right of point deleted"))) (message "word right of point deleted")))
(defun viking--kill-space() (defun viking--kill-space()
;; FIXME: might be better to implement this myself "Kill space around point, including newline(s), but the first."
;; so that all space+newlines will be deleted but
;; the last one, which is sometimes better...
"Kill space around point, including newline(s)."
(interactive) (interactive)
(let ((beg (save-excursion (skip-chars-backward " \t\r\n") (point))) (let* ((lineA 0) (lineB 0)
(end (save-excursion (skip-chars-forward " \t\r\n") (point)))) (beg (save-excursion
(viking--blink-region beg end)) (skip-chars-backward " \t\r\n")
(just-one-space -1) (cond ((looking-at "\r\n")
(message "spaces cleared")) (forward-char 2))
((looking-at "\n")
(forward-char 1)))
(setq lineA (line-number-at-pos))
(point)))
(end (save-excursion
(skip-chars-forward " \t\r\n")
(setq lineB (line-number-at-pos))
(point)))
)
(viking--blink-region beg end)
(if (= lineA lineB)
(just-one-space)
(delete-region beg end))
(message "spaces cleared")))
;;;;; Public interactive kill functions ;;;;; Public interactive kill functions
@@ -405,9 +417,8 @@ kill function then."
map)) map))
;; just in case someone wants to use it globally ;; just in case someone wants to use it globally
(define-global-minor-mode viking-global-mode (define-globalized-minor-mode viking-global-mode
viking-mode viking-mode viking-mode
(lambda () (viking-mode t))
:group 'viking-mode :group 'viking-mode
) )