From 7675a3c395e0da4d30a7a46ea74680271469f9a5 Mon Sep 17 00:00:00 2001 From: TLINDEN Date: Sat, 28 May 2016 12:58:19 +0200 Subject: [PATCH] addressed issue#3: renamed viking-kill-functions, added viking-repeat-last-kill --- README.md | 21 +++++++++++++++++++- viking-mode.el | 52 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e36b298..7c9df69 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ Like: However, this only works when pressing the key in a row. If you do something else in between, it starts from scratch (i.e. delete word). +You can also repeat the last delete function with C-S-d (ctrl-shift-d) +multiple times. + By default viking-mode is greedy: after applying a kill function it looks if point ends up alone on an empty line or inside whitespaces. In such a case, those will be deleted as well. The greedy behavior may @@ -76,6 +79,10 @@ You can change the default key binding by: (define-key viking-mode-map (kbd "C-k") 'viking-kill-thing-at-point) +The key binding to repeat the last kill function can be changed: + + (define-key viking-mode-map (kbd "M-d") 'viking-repeat-last-kill) + In case you don't like the default key binding cascade, you may also use separate bindings for each kill function, e.g.: @@ -96,6 +103,18 @@ Also, the font face of the short highlight can be modified: M-x customize-face (select viking-blink) +The kill functions to be called in a row can be customized as well. The +default is this list: + + (setq vikink-kill-functions (list 'viking-kill-word + 'viking-kill-line-from-point + 'viking-kill-line + 'viking-kill-paragraph + 'viking-kill-buffer)) + +Normally there should be no need to modify it. However, this gives +you much more flexibility. + Or, modify all available viking-mode variables interactively with: M-x customize-group (select viking-mode) @@ -171,7 +190,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -Version : 0.07 +Version : 0.08 Author : T.v.Dein Keywords : kill delete URL : https://github.com/tlinden/viking-mode diff --git a/viking-mode.el b/viking-mode.el index f1afec3..f19cd85 100644 --- a/viking-mode.el +++ b/viking-mode.el @@ -19,7 +19,7 @@ ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ;; USA -;; Version: 0.07 +;; Version: 0.08 ;; Author: T.v.Dein ;; Keywords: kill delete ;; URL: https://github.com/tlinden/viking-mode @@ -54,6 +54,9 @@ ;; something else in between, it starts from scratch (i.e. delete ;; word). +;; You can also repeat the last delete function with C-S-d (ctrl-shift-d) +;; multiple times. + ;; By default viking-mode is greedy: after applying a kill function it ;; looks if point ends up alone on an empty line or inside ;; whitespaces. In such a case, those will be deleted as well. The @@ -102,6 +105,10 @@ ;; (define-key viking-mode-map (kbd "C-k") 'viking-kill-thing-at-point) +;; The key binding to repeat the last kill function can be changed: + +;; (define-key viking-mode-map (kbd "M-d") 'viking-repeat-last-kill) + ;; In case you don't like the default key binding cascade, you may ;; also use separate bindings for each kill function, e.g.: @@ -125,9 +132,11 @@ ;; The kill functions to be called in a row can be customized as well. The ;; default is this list: -;; (setq vikink-kill-funcs (list 'viking-kill-word 'viking-kill-line-from-point -;; 'viking-kill-line 'viking-kill-paragraph -;; 'viking-kill-buffer)) +;; (setq vikink-kill-functions (list 'viking-kill-word +;; 'viking-kill-line-from-point +;; 'viking-kill-line +;; 'viking-kill-paragraph +;; 'viking-kill-buffer)) ;; Normally there should be no need to modify it. However, this gives ;; you much more flexibility. @@ -191,7 +200,7 @@ ;;; Code: ;;;; Consts -(defconst viking-mode-version "0.07" "Viking Mode version.") +(defconst viking-mode-version "0.08" "Viking Mode version.") (defgroup viking-mode nil "Kill first, ask later - an emacs mode for killing things quickly" @@ -237,13 +246,18 @@ and active for the current major mode, then use its expansions to mark regions and delete them." :group 'viking-mode) -(defcustom viking-kill-funcs (list 'viking-kill-word 'viking-kill-line-from-point 'viking-kill-line 'viking-kill-paragraph 'viking-kill-buffer) +(defcustom viking-kill-functions (list 'viking-kill-word 'viking-kill-line-from-point 'viking-kill-line 'viking-kill-paragraph 'viking-kill-buffer) "The actual kill functions being called in a row starting with the first entry" :group 'viking-mode) -;; internal copy +;;;;; Internal variables + +;; internal copy of kill functions without the last one executed will +;; be reset to original list every time key pressed the first time (defvar viking--current-killf ()) +;; holds last kill function executed so we can repeat it when needed +(defvar viking--last-killf (car viking-kill-functions)) ;;;; Functions ;;;;; Utilities @@ -368,19 +382,26 @@ should be a point-moving function." (message "region deleted")) +(defun viking--next-killf() + "Return next kill function, update 'viking--current-killf and +'viking--last-killf." + (setq viking--last-killf (pop viking--current-killf)) + viking--last-killf) + + (defun viking--killw (count) "execute kill function from the list of kill functions in 'viking--current-killf, reset it to the contents of -'viking-kill-funcs if COUNT is 1 (thus the command key has been +'viking-kill-functions if COUNT is 1 (thus the command key has been pressed the first time in a row" (progn ;; start from scratch (if (eq count 1) - (setq viking--current-killf viking-kill-funcs)) + (setq viking--current-killf viking-kill-functions)) ;; only call killer if not done killing (if (and viking--current-killf (not (eobp))) - (funcall (pop viking--current-killf)) + (funcall (viking--next-killf)) (signal 'end-of-buffer nil) ))) @@ -407,7 +428,7 @@ If 'viking-greedy-kill is t, clean up spaces and newlines afterwards." (progn (viking--kill-space) ;; reset kill func list: - (setq viking--current-killf viking-kill-funcs)) + (setq viking--current-killf viking-kill-functions)) (progn (if (or (eq (point) (line-beginning-position)) (memq (preceding-char) '(?\t ?\ ))) @@ -472,7 +493,7 @@ If 'viking-greedy-kill is t, clean up spaces and newlines afterwards." (viking--kill-region beg end) (message "buffer deleted")))) -;;;;; Primary key binding function +;;;;; Primary key binding functions (defun viking-kill-thing-at-point() @@ -485,6 +506,12 @@ kill function then." (viking--killw (viking-last-key-repeats)))) +(defun viking-repeat-last-kill() + (interactive) + "Repeat the last executed kill function" + (funcall viking--last-killf)) + + ;;;; Interface ;;;###autoload @@ -494,6 +521,7 @@ kill function then." :group 'viking-mode :keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "C-d") 'viking-kill-thing-at-point) + (define-key map (kbd "C-S-D") 'viking-repeat-last-kill) map)) ;; just in case someone wants to use it globally