1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
diff --git a/src/buffer.c b/src/buffer.c
index bbb487c6..9656418c 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -436,6 +436,16 @@ warn_if_readonly_buffer (void)
return false;
}
+bool
+check_if_no_mark (void) {
+ if ((!cur_bp->mark) ||
+ (!get_buffer_mark_active (cur_bp)))
+ {
+ return true;
+ }
+ return false;
+}
+
bool
warn_if_no_mark (void)
{
diff --git a/src/extern.h b/src/extern.h
index 277e1619..2b04edc3 100644
--- a/src/extern.h
+++ b/src/extern.h
@@ -74,6 +74,7 @@ _GL_ATTRIBUTE_PURE const char *get_buffer_filename_or_name (Buffer bp);
void set_buffer_names (Buffer bp, const char *filename);
_GL_ATTRIBUTE_PURE Buffer find_buffer (const char *name);
void switch_to_buffer (Buffer bp);
+bool check_if_no_mark (void);
bool warn_if_no_mark (void);
bool warn_if_readonly_buffer (void);
#define FIELD(ty, field) \
diff --git a/src/killring.c b/src/killring.c
index 750acb1d..50753ac7 100644
--- a/src/killring.c
+++ b/src/killring.c
@@ -211,6 +211,34 @@ kill_text (long uniarg, Function mark_func)
return true;
}
+DEFUN_ARGS ("kill-region-or-backward-kill-word",
+ kill_region_or_backward_kill_word,
+ INT_OR_UNIARG (arg))
+/*+
+Kill (\"cut\") text between point and mark, if they are both
+active, otherwise performs \\[backward-kill-word]. This deletes the
+text from the buffer and saves it in the kill ring. The command
+\\[yank] can retrieve it from there.
+
+Any command that calls this function is a \"kill command\". If the
+previous command was also a kill command, the text killed this time
+appends to the text killed last time to make one entry in the kill
+ring.
+
+If the buffer is read-only, Zile will beep and refrain from deleting
+the text, but put the text in the kill ring anyway. This means that
+you can use the killing commands to copy text from a read-only buffer.
++*/
+{
+ INT_OR_UNIARG_INIT (arg);
+ if (check_if_no_mark ()) {
+ ok = kill_text (-arg, F_mark_word);
+ } else {
+ ok = copy_or_kill_the_region(true);
+ }
+}
+END_DEFUN
+
DEFUN_ARGS ("kill-word", kill_word,
INT_OR_UNIARG (arg))
/*+
diff --git a/src/tbl_bindings.pl b/src/tbl_bindings.pl
index 61240d15..797e3bfa 100644
--- a/src/tbl_bindings.pl
+++ b/src/tbl_bindings.pl
@@ -70,7 +70,7 @@
"keyboard-quit" => ["\\C-g"],
"kill-buffer" => ["\\C-xk"],
"kill-line" => ["\\C-k"],
- "kill-region" => ["\\C-w"],
+ "kill-region-or-backward-kill-word" => ["\\C-w"],
"kill-sexp" => ["\\C-\\M-k"],
"kill-word" => ["\\M-d"],
"list-buffers" => ["\\C-x\\C-b"],
|