mirror of
https://codeberg.org/scip/viking-mode.git
synced 2025-12-18 04:51:00 +01:00
added basic expand-region support, note enabled by default; fixed viking-kill-region()
This commit is contained in:
13
README.md
13
README.md
@@ -37,6 +37,11 @@ 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
|
In such a case, those will be deleted as well. The greedy behavior may
|
||||||
be turned off however.
|
be turned off however.
|
||||||
|
|
||||||
|
Another variant is to use viking mode together with the great
|
||||||
|
expand-region mode (available on melpa). If installed and enabled, a
|
||||||
|
region is first marked using expand-region and then deleted. This
|
||||||
|
makes the deletion cascade language aware.
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
To use, save viking-mode.el to a directory in your load-path.
|
To use, save viking-mode.el to a directory in your load-path.
|
||||||
@@ -81,6 +86,12 @@ use separate bindings for each kill function, e.g.:
|
|||||||
(define-key viking-mode-map (kbd "C-d p") 'viking-kill-paragraph)
|
(define-key viking-mode-map (kbd "C-d p") 'viking-kill-paragraph)
|
||||||
(define-key viking-mode-map (kbd "C-d a") 'viking-kill-buffer)
|
(define-key viking-mode-map (kbd "C-d a") 'viking-kill-buffer)
|
||||||
|
|
||||||
|
To use viking-mode with expand-region:
|
||||||
|
|
||||||
|
(setq viking-use-expand-region-when-loaded t)
|
||||||
|
(require 'expand-region)
|
||||||
|
(global-set-key (kbd "C-=") 'er/expand-region)
|
||||||
|
|
||||||
Also, the font face of the short highlight can be modified:
|
Also, the font face of the short highlight can be modified:
|
||||||
|
|
||||||
M-x customize-face (select viking-blink)
|
M-x customize-face (select viking-blink)
|
||||||
@@ -160,7 +171,7 @@ along with this program; if not, write to the Free Software
|
|||||||
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.02
|
Version : 0.07
|
||||||
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
|
||||||
|
|||||||
@@ -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.06
|
;; Version: 0.07
|
||||||
;; 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
|
||||||
@@ -59,6 +59,11 @@
|
|||||||
;; whitespaces. In such a case, those will be deleted as well. The
|
;; whitespaces. In such a case, those will be deleted as well. The
|
||||||
;; greedy behavior may be turned off however.
|
;; greedy behavior may be turned off however.
|
||||||
|
|
||||||
|
;; Another variant is to use viking mode together with the great
|
||||||
|
;; expand-region mode (available on melpa). If installed and enabled,
|
||||||
|
;; a region is first marked using expand-region and then deleted.
|
||||||
|
;; This makes the deletion cascade language aware.
|
||||||
|
|
||||||
;;; Install:
|
;;; Install:
|
||||||
|
|
||||||
;; To use, save viking-mode.el to a directory in your load-path.
|
;; To use, save viking-mode.el to a directory in your load-path.
|
||||||
@@ -107,6 +112,12 @@
|
|||||||
;; (define-key viking-mode-map (kbd "C-d p") 'viking-kill-paragraph)
|
;; (define-key viking-mode-map (kbd "C-d p") 'viking-kill-paragraph)
|
||||||
;; (define-key viking-mode-map (kbd "C-d a") 'viking-kill-buffer)
|
;; (define-key viking-mode-map (kbd "C-d a") 'viking-kill-buffer)
|
||||||
|
|
||||||
|
;; To use viking-mode with expand-region:
|
||||||
|
|
||||||
|
;; (setq viking-use-expand-region-when-loaded t)
|
||||||
|
;; (require 'expand-region)
|
||||||
|
;; (global-set-key (kbd "C-=") 'er/expand-region)
|
||||||
|
|
||||||
;; Also, the font face of the short highlight can be modified:
|
;; Also, the font face of the short highlight can be modified:
|
||||||
|
|
||||||
;; M-x customize-face (select viking-blink)
|
;; M-x customize-face (select viking-blink)
|
||||||
@@ -180,7 +191,7 @@
|
|||||||
;;; Code:
|
;;; Code:
|
||||||
;;;; Consts
|
;;;; Consts
|
||||||
|
|
||||||
(defconst viking-mode-version "0.06" "Viking Mode version.")
|
(defconst viking-mode-version "0.07" "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"
|
||||||
@@ -220,6 +231,12 @@ deleted after the kill function, if any. Uses 'just-one-space."
|
|||||||
mark is set."
|
mark is set."
|
||||||
:group 'viking-mode)
|
:group 'viking-mode)
|
||||||
|
|
||||||
|
(defcustom viking-use-expand-region-when-loaded nil
|
||||||
|
"If set to true (default: nil) and expand-region is installed
|
||||||
|
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-funcs (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"
|
"The actual kill functions being called in a row starting with the first entry"
|
||||||
:group 'viking-mode)
|
:group 'viking-mode)
|
||||||
@@ -346,8 +363,8 @@ should be a point-moving function."
|
|||||||
"Kill region at point, if any"
|
"Kill region at point, if any"
|
||||||
(interactive)
|
(interactive)
|
||||||
(if viking-really-delete
|
(if viking-really-delete
|
||||||
(delete-region (point-min) (point-max) t)
|
(delete-region (mark) (point))
|
||||||
(kill-region (point-min) (point-max) t))
|
(kill-region (mark) (point)))
|
||||||
(message "region deleted"))
|
(message "region deleted"))
|
||||||
|
|
||||||
|
|
||||||
@@ -356,15 +373,24 @@ should be a point-moving function."
|
|||||||
'viking--current-killf, reset it to the contents of
|
'viking--current-killf, reset it to the contents of
|
||||||
'viking-kill-funcs if COUNT is 1 (thus the command key has been
|
'viking-kill-funcs if COUNT is 1 (thus the command key has been
|
||||||
pressed the first time in a row"
|
pressed the first time in a row"
|
||||||
;; start from scratch
|
(progn
|
||||||
(if (eq count 1)
|
;; start from scratch
|
||||||
(setq viking--current-killf viking-kill-funcs))
|
(if (eq count 1)
|
||||||
|
(setq viking--current-killf viking-kill-funcs))
|
||||||
|
|
||||||
|
;; only call killer if not done killing
|
||||||
|
(if (and viking--current-killf (not (eobp)))
|
||||||
|
(funcall (pop viking--current-killf))
|
||||||
|
(signal 'end-of-buffer nil)
|
||||||
|
)))
|
||||||
|
|
||||||
;; only call killer if not done killing
|
|
||||||
(if (and viking--current-killf (not (eobp)))
|
(defun viking--er-killw ()
|
||||||
(funcall (pop viking--current-killf))
|
"executes er/expand-region (if loaded and enabled) and deletes
|
||||||
(signal 'end-of-buffer nil)
|
the region marked by it, thus making viking language aware."
|
||||||
))
|
(er/expand-region 1)
|
||||||
|
(sit-for viking-blink-time)
|
||||||
|
(viking-kill-region))
|
||||||
|
|
||||||
|
|
||||||
;;;;; Public interactive kill functions
|
;;;;; Public interactive kill functions
|
||||||
@@ -454,7 +480,9 @@ If 'viking-greedy-kill is t, clean up spaces and newlines afterwards."
|
|||||||
calling key has been pressed and runs the appropriate
|
calling key has been pressed and runs the appropriate
|
||||||
kill function then."
|
kill function then."
|
||||||
(interactive)
|
(interactive)
|
||||||
(viking--killw (viking-last-key-repeats)))
|
(if (and (fboundp 'er/expand-region) viking-use-expand-region-when-loaded)
|
||||||
|
(viking--er-killw)
|
||||||
|
(viking--killw (viking-last-key-repeats))))
|
||||||
|
|
||||||
|
|
||||||
;;;; Interface
|
;;;; Interface
|
||||||
|
|||||||
Reference in New Issue
Block a user