-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhole-line-or-region.el
644 lines (547 loc) · 26.5 KB
/
whole-line-or-region.el
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
;;; @(#) whole-line-or-region.el -- operate on current line if region undefined
;;; @(#) $Id: whole-line-or-region.el,v 1.3 2008/12/06 03:31:32 joe Exp $
;; This file is not part of Emacs
;; Copyright (C) 2001 by Joseph L. Casadonte Jr.
;; Author: Joe Casadonte ([email protected])
;; Maintainer: Joe Casadonte ([email protected])
;; Created: July 1, 2001
;; Keywords: kill yank cut copy paste whole lines
;; Latest Version: http://www.northbound-train.com/emacs.html
;; COPYRIGHT NOTICE
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;; This minor mode allows functions to operate on the current line if
;; they would normally operate on a region and region is currently
;; undefined.
;;
;; The primary use for this is to kill (cut) the current line if no
;; region is defined, and kill-region is invoked. It basically saves
;; you the effort of going to the begining of the line, selecting the
;; text up to the end of the line, and killing. Similarly, when
;; yanking, it's smart enough to know that the string to be yanked
;; was killed as a whole line, and it should be yanked as one, too.
;; So you don't need to position yourself at the start of the line
;; before yanking. If region *is* defined, though, all functions act
;; as normal.
;;
;; The inspiration for this came from an old editor I used to use
;; (brief maybe?), that did this exact thing for you. It was a handy
;; feature to have, and I definitely wanted it when I moved to Emacs.
;; I've extended the concept slightly, to let you copy N whole lines,
;; using the standard prefix method.
;;
;; NOTE: This package will behave unexpectedly (and indeed is nearly
;; useless) if `transient-mark-mode' is off, as there is then always
;; a region defined.
;;
;; NOTE: I haven't gotten this to work under XEmacs (though I
;; honestly haven't tried real hard).
;;; Usage:
;;
;; M-x `whole-line-or-region-mode'
;; Toggles whole-line-or-region-mode on & off. Optional arg turns
;; whole-line-or-region-mode on iff arg is a positive integer. Then
;; just call functions `copy-region-as-kill', `kill-region',
;; `kill-ring-save' and `yank' as you normally would.
;;
;; To turn the mode on automatically whenever Emacs starts, customize
;; `whole-line-or-region-mode' (which see).
;;; Extending Package:
;;
;; I've tried to make the base functions as generic as possible so
;; that this same concept can be used for other region-based
;; functions. The only function I've thought of to date to extend in
;; this manner is `comment-dwim'. Examples using `comment-dwim'
;; follow.
;;
;; In order to extend this package for additional region-based
;; functions, you must understand how those functions work, and write
;; a new stub function that will be used to replace it. One of two
;; whole-line-or-region functions must be called from within that
;; stub; which one to use depends on whether or not the original
;; function wants region passed into it, or assumes region is defined
;; before being called.
;;
;; Using `kill-region' as an example, looking at its definition we
;; see that it takes two arguments, BEG and END. Looking at it
;; another way, it's interactive declaration is "r", which says to
;; pass in the current region. Because of this, the stub function
;; for it should call `whole-line-or-region-call-with-region':
;;
;; (defun whole-line-or-region-kill-region (prefix)
;; "Kill region or PREFIX whole lines."
;; (interactive "*p")
;; (whole-line-or-region-call-with-region 'kill-region prefix t))
;;
;; The first argument to `whole-line-or-region-call-with-region' is
;; the function being replaced. The second is the value for prefix,
;; so that the stub can operate on more than just one line (e.g. C-u
;; 12 M-w would copy 12 whole lines). Other arguments are explained
;; in the function documentation.
;;
;; The function `comment-dwim', on the other hand, expects region to
;; be defined coming in, so its stub should call into the other
;; whole-line stub, `whole-line-or-region-call-with-prefix'. There are
;; things to consider, though. The original `comment-dwim' wants a
;; raw prefix value, but it doesn't use it to work over a variable
;; number of lines; rather it uses it to signal what DWIM really
;; does. Sort of defeats the purpose of a DWIM command, if you ask
;; me -- it should be simple enough to determine from the current
;; context what DWIMs should do. I digress, however.....
;;
;; The "proper" way to write a whole-line version of `comment-dwim'
;; would be like the following:
;;
;; (defun whole-line-or-region-comment-dwim (raw-prefix)
;; "Call `comment-dwim' on current region or current line."
;; (interactive "*P")
;; (whole-line-or-region-call-with-prefix 'comment-dwim 1 nil t raw-prefix))
;;
;; The arguments for `whole-line-or-region-call-with-prefix' are
;; basically the same as for `whole-line-or-region-call-with-region',
;; but how each of them call the original function differs. The
;; first one calls it with two arguments (i.e. region's BEG & END)
;; and the second one sets mark (i.e. defines region) and passes in
;; prefix (raw or processed, depending).
;;
;; So the above example for `comment-dwim' would call the original
;; function with the current region (if defined) or the current line
;; (the second argument, the number of lines to operate on, being
;; hard-coded to 1), also passing in the raw prefix, for use within
;; the original function. It retains its original semantics and just
;; saves you from having to mark the current line.
;;
;; It could instead be defined like so:
;;
;; (defun whole-line-or-region-comment-dwim-2 (prefix)
;; "Call `comment-dwim' on region or PREFIX whole lines."
;; (interactive "*p")
;; (whole-line-or-region-call-with-prefix 'comment-dwim prefix nil t))
;;
;; What this version does is override the normal behavior of the
;; prefix arg to `comment-dwim', and instead uses it to indicate how
;; many lines the whole-line version will comment out -- no prefix
;; value is passed to the original function in this case. This is
;; the version that I use, as it's just more intuitive for me.
;;
;; After defining the new stub, however you do it, the package needs
;; to know about it so that it can toggle its use on and off as the
;; mode toggles on and off. For that you need to customize the
;; variable `whole-line-or-region-extensions-alist', telling it the
;; original function name (`comment-dwim') and the new one
;; (`whole-line-or-region-comment-dwim-2'). If you want to limit the
;; redefinition to a specific keymap then specify that as well;
;; otherwise, the rebinding will occur in the global keymap.
;; Rebinding occurs via `substitute-key-definition' (which see).
;;; To Do:
;;
;; o Nothing, at the moment.
;;; Comments:
;;
;; Any comments, suggestions, bug reports or upgrade requests are welcome.
;; Please send them to Joe Casadonte ([email protected]).
;;
;; This version of whole-line-or-region was developed and tested with NTEmacs
;; 22.2.1 under Windows XP Pro. Please, let me know if it works with
;; other OS and versions of Emacs.
;;; Change Log:
;;
;; see http://www.northbound-train.com/emacs/whole-line-or-region.log
;;; **************************************************************************
;;; **************************************************************************
;;; **************************************************************************
;;; **************************************************************************
;;; **************************************************************************
;;; Code:
(eval-when-compile
;; silence the old byte-compiler
(defvar byte-compile-dynamic nil)
(set (make-local-variable 'byte-compile-dynamic) t))
;;; **************************************************************************
;;; ***** version related routines
;;; **************************************************************************
(defconst whole-line-or-region-version
"$Revision: 1.3 $"
"Version number for 'whole-line-or-region' package.")
;; ---------------------------------------------------------------------------
(defun whole-line-or-region-version-number ()
"Return 'whole-line-or-region' version number."
(string-match "[0123456789.]+" whole-line-or-region-version)
(match-string 0 whole-line-or-region-version))
;; ---------------------------------------------------------------------------
(defun whole-line-or-region-display-version ()
"Display 'whole-line-or-region' version."
(interactive)
(message "whole-line-or-region version <%s>." (whole-line-or-region-version-number)))
;;; **************************************************************************
;;; ***** customization
;;; **************************************************************************
(defgroup whole-line-or-region nil
"Customization group for whole-line-or-region minor mode."
:group 'editing-basics
:group 'convenience)
;; ---------------------------------------------------------------------------
(defun whole-line-or-region-customize ()
"Customization of the group 'whole-line-or-region'."
(interactive)
(customize-group "whole-line-or-region"))
;; ---------------------------------------------------------------------------
(defcustom whole-line-or-region-mode nil
"Non-nil if whole-line-or-region minor mode is enabled.
Setting this variable directly does not take effect; use either
\\[customize] or the function `whole-line-or-region-mode'."
:set (lambda (symbol value)
(whole-line-or-region-mode (or value 0)))
:initialize 'custom-initialize-default
:type 'boolean
:group 'whole-line-or-region)
;; ---------------------------------------------------------------------------
(defcustom whole-line-or-region-extensions-alist '(
(copy-region-as-kill whole-line-or-region-copy-region-as-kill nil)
(kill-region whole-line-or-region-kill-region nil)
(kill-ring-save whole-line-or-region-kill-ring-save nil)
(yank whole-line-or-region-yank nil)
)
"List of functions for whole-line-or-region to swap.
When whole-line-or-region is activated, all original functions will be
replaced with their whole-line counterparts in the global keymap,
unless the optional keymap is specified (in which case it will be
replace in that map only). Similarly, when whole-line-or-region is
de-activated, the functions will be swapped back.
The default is to map the following:
o `copy-region-as-kill' -> `whole-line-or-region-copy-region-as-kill'
o `kill-region' -> `whole-line-or-region-kill-region'
o `kill-ring-save' -> `whole-line-or-region-kill-ring-save'
o `yank' -> `whole-line-or-region-yank'
In addition, the following functions are provided by the package for
your convenience:
o `whole-line-or-region-delete'
o `whole-line-or-region-comment-dwim'
o `whole-line-or-region-comment-dwim-2'
See the individual functions for more information on what they do and
suggested mappings."
:type '(repeat
(list :tag "Function Mappings:"
(function :tag "Original Function")
(function :tag "Whole-line Version")
(variable :tag "Keymap (optional)")
))
:group 'whole-line-or-region
:set (lambda (symbol newval)
(set symbol newval)
(when whole-line-or-region-mode
(whole-line-or-region-bind-keys)))
)
;; ---------------------------------------------------------------------------
(defcustom whole-line-or-region-mode-line-string " WLR"
"String to display in mode-line when 'whole-line-or-region' is active.
Must start with a space. Changes will take effect next time emacs is
started."
:type 'string
:group 'whole-line-or-region)
;; ---------------------------------------------------------------------------
(defcustom whole-line-or-region-load-hook nil
"Hook to run when package is loaded."
:type 'hook
:group 'whole-line-or-region)
;; ---------------------------------------------------------------------------
(defcustom whole-line-or-region-on-hook nil
"Hook called when 'whole-line-or-region' mode is turned on."
:type 'hook
:group 'whole-line-or-region)
;; ---------------------------------------------------------------------------
(defcustom whole-line-or-region-off-hook nil
"Hook called when 'whole-line-or-region' mode is turned off."
:type 'hook
:group 'whole-line-or-region)
;;; **************************************************************************
;;; ***** minor mode functions
;;; **************************************************************************
; (defvar whole-line-or-region-mode nil )
;;; --------------------------------------------------------------------------
;;;###autoload
(defun whole-line-or-region-mode (&optional arg)
"Toggle use of whole-line-or-region minor mode.
This minor mode allows functions to operate on the current line if
they would normally operate on a region and region is currently
undefined.
Optional ARG turns mode on iff ARG is a positive integer."
(interactive "P")
;; toggle on and off
(let ((old-mode whole-line-or-region-mode))
(setq whole-line-or-region-mode
(if arg (or (listp arg)
(> (prefix-numeric-value arg) 0))
(not whole-line-or-region-mode)))
(when (not (equal old-mode whole-line-or-region-mode))
;; enable/disable advice
(if whole-line-or-region-mode
(whole-line-or-region-bind-keys)
(whole-line-or-region-restore-keys))
(run-hooks (if whole-line-or-region-mode
'whole-line-or-region-on-hook
'whole-line-or-region-off-hook))
)))
;; ---------------------------------------------------------------------------
;; add to minor-mode-alist if not there already
(or
(assq 'whole-line-or-region-mode minor-mode-alist)
(setq minor-mode-alist
(cons
(list 'whole-line-or-region-mode whole-line-or-region-mode-line-string)
minor-mode-alist)))
;;; **************************************************************************
;;; ***** interactive functions (used by default)
;;; **************************************************************************
;;;###autoload
(defun whole-line-or-region-copy-region-as-kill (prefix)
"Copy region or PREFIX whole lines."
(interactive "p")
(whole-line-or-region-call-with-region 'copy-region-as-kill prefix t))
;;; --------------------------------------------------------------------------
;; (defalias 'whole-line-or-region-copy 'whole-line-or-region-copy-region-as-kill)
;;; **************************************************************************
;;;###autoload
(defun whole-line-or-region-kill-region (prefix)
"Kill (cut) region or PREFIX whole lines."
(interactive "*p")
(whole-line-or-region-call-with-region 'kill-region prefix t))
;;; **************************************************************************
;;;###autoload
(defun whole-line-or-region-kill-ring-save (prefix)
"Copy region or PREFIX whole lines."
(interactive "p")
(whole-line-or-region-call-with-region 'kill-ring-save prefix t))
;;; **************************************************************************
;;;###autoload
(defun whole-line-or-region-yank (raw-prefix &optional string-in)
"Yank (paste) previously killed text.
If the text to be yanked was killed with a whole-line-or-region
function *as* a whole-line, then paste it as a whole line (i.e. do not
break up the current line, and do not force the user to move point).
RAW-PREFIX is used to determine which string to yank, just as `yank'
would normally use it.
Optionally, pass in string to be \"yanked\" via STRING-IN."
(interactive "*P")
;; figure out what yank would do normally
(let ((string-to-yank (or string-in (current-kill
(cond ((listp raw-prefix) 0)
((eq raw-prefix '-) -1)
(t (1- raw-prefix))) t)))
(saved-column (current-column)))
;; check for whole-line prop in yanked text
(if (get-text-property 0 'whole-line-or-region string-to-yank)
(let ((beg (line-beginning-position)))
;; goto beg of line and yank
(beginning-of-line)
(if string-in
;; insert "manually"
(insert string-in)
;; just yank as normal
(yank raw-prefix))
;; a whole-line killed from end of file may not have a
;; trailing newline -- add one, in these cases
(when (not (string-match "\n$" string-to-yank))
(insert "\n")
'(lambda () (interactive) (previous-line 1)))
;; restore state of being....
(move-to-column saved-column)
(remove-text-properties beg (+ beg 1) '(whole-line-or-region nil)))
;; no whole-line-or-region mark
(if string-in
;; insert "manually"
(progn
(when (and delete-selection-mode
mark-active)
(delete-active-region))
(insert string-in))
;; just yank as normal
(yank raw-prefix)))
))
;;; --------------------------------------------------------------------------
;; in case delete-selection-mode (delsel.el) is being used
(if (string-match "Emacs 21" (emacs-version))
(put 'whole-line-or-region-yank 'delete-selection 'yank)
(put 'whole-line-or-region-yank 'delete-selection t))
;;; **************************************************************************
;;; alternate interactive functions
;;; **************************************************************************
;;;###autoload
(defun whole-line-or-region-delete (prefix)
"Delete region or PREFIX whole lines."
(interactive "*p")
(whole-line-or-region-call-with-region 'delete-region prefix))
;;; **************************************************************************
;;;###autoload
(defun whole-line-or-region-comment-dwim (raw-prefix)
"Call `comment-dwim' on current region or current line.
See `comment-dwim' for details of RAW-PREFIX usage."
(interactive "*P")
(whole-line-or-region-call-with-prefix 'comment-dwim 1 nil t raw-prefix))
;;; **************************************************************************
;;;###autoload
(defun whole-line-or-region-comment-dwim-2 (prefix)
"Call `comment-dwim' on region or PREFIX whole lines."
(interactive "*p")
(whole-line-or-region-call-with-prefix 'comment-dwim prefix nil t))
;;; **************************************************************************
;;; ***** internal functions
;;; **************************************************************************
(defun whole-line-or-region-call-with-region (fn &optional cnt mark-as-whole send-prefix prefix)
"Calls FN on region or CNT whole lines.
If region is defined simply call FN, passing in the start and end of
the current region.
If region is not currently defined, then define it temporarily as the
current line. Additionally, if CNT is set, expand region to cover the
next CNT whole lines (or previous CNT whole lines, if CNT is
negative). Before FN is called, mark the temporary region with a
special property if MARK-AS-WHOLE is non-nil (this is useful if the
text could be worked on with some future whole-line-or-region
function, and it makes sense to understand the context in which FN was
originally called, e.g. killing and yanking text; see
`whole-line-or-region-yank' for an example).
In either case, if SEND-PREFIX is non-nil, then PREFIX is passed into
FN as a third argument."
(whole-line-or-region-base-call fn fn t nil nil cnt mark-as-whole send-prefix prefix))
;;; **************************************************************************
(defun whole-line-or-region-call-with-prefix (fn &optional cnt mark-as-whole send-prefix prefix)
"Calls FN on region or CNT whole lines.
If region is defined simply call FN.
If region is not currently defined, then define it temporarily as the
current line. Additionally, if CNT is set, expand region to cover the
next CNT whole lines (or previous CNT whole lines, if CNT is
negative). Before FN is called, mark the temporary region with a
special property if MARK-AS-WHOLE is non-nil (this is useful if the
text could be worked on with some future whole-line-or-region
function, and it makes sense to understand the context in which FN was
originally called, e.g. killing and yanking text; see
`whole-line-or-region-yank' for an example).
In either case, if SEND-PREFIX is non-nil, then PREFIX is passed into
FN as the sole argument."
(whole-line-or-region-base-call fn fn nil nil nil cnt mark-as-whole send-prefix prefix))
;;; **************************************************************************
(defun whole-line-or-region-base-call (norm-fn wlr-fn
&optional beg-end pre-args post-args
cnt mark-as-whole send-prefix prefix)
"Calls FN on region or CNT whole lines.
If region is defined simply call NORM-FN.
If region is not currently defined, then define it temporarily as the
current line. Additionally, if CNT is set, expand region to cover the
next CNT whole lines (or previous CNT whole lines, if CNT is
negative). Before WLR-FN is called, mark the temporary region with a
special property if MARK-AS-WHOLE is non-nil (this is useful if the
text could be worked on with some future whole-line-or-region
function, and it makes sense to understand the context in which WLR-FN was
originally called, e.g. killing and yanking text; see
`whole-line-or-region-yank' for an example).
In either case, if BEG-END is non-nil, then pass into FN the start and
end of the current region. PRE-ARGS and POST-ARGS are lists of
arguments to be passed into FN before \(PRE-ARGS) and/or after
\(POST-ARGS) the start and end of the current region (but only if
BEG-END is non-nil). Finally, if SEND-PREFIX is non-nil, then PREFIX
is passed into FN before POST-ARGS."
;; region is defined, so just do what should normally be done
(if (and mark-active
(/= (point) (mark)))
;; just call it, but make sure to pass all of the arguments....
(let (args)
(when pre-args
(whole-line-or-region-append-to-list 'args pre-args))
(when beg-end
(whole-line-or-region-append-to-list 'args (point))
(whole-line-or-region-append-to-list 'args (mark)))
(when send-prefix
(whole-line-or-region-append-to-list 'args (list prefix)))
(when post-args
(whole-line-or-region-append-to-list 'args post-args))
(apply 'funcall norm-fn args))
;; no region defined, act on whole line
(let ((saved-column (current-column))
(current-mod-state (buffer-modified-p))
beg end)
(save-excursion
(setq beg (line-beginning-position))
(set-mark beg)
;; add whole-line property, sometimes
(when mark-as-whole
(let ((inhibit-read-only t))
(put-text-property beg (+ beg 1) 'whole-line-or-region t)
(set-buffer-modified-p current-mod-state)))
(setq end (line-beginning-position (+ (or cnt 1) 1)))
(goto-char end)
(let (args)
(when pre-args
(whole-line-or-region-append-to-list 'args pre-args))
(when beg-end
(whole-line-or-region-append-to-list 'args beg)
(whole-line-or-region-append-to-list 'args end))
(when send-prefix
(whole-line-or-region-append-to-list 'args (list prefix)))
(when post-args
(whole-line-or-region-append-to-list 'args post-args))
(apply 'funcall wlr-fn args))
;; remove whole-line property, sometimes
(when mark-as-whole
(let ((inhibit-read-only t)
(current-mod-state (buffer-modified-p)))
(remove-text-properties beg (+ beg 1) '(whole-line-or-region nil))
(set-buffer-modified-p current-mod-state)))
)
(move-to-column saved-column))
))
;;; **************************************************************************
(defun whole-line-or-region-bind-keys (&optional switch)
"Bind keys according to `whole-line-or-region-extensions-alist'.
With optional SWITCH, restore keys instead."
(let ((gmap (current-global-map))
(ext-alist whole-line-or-region-extensions-alist)
elem orig wlr map)
(while ext-alist
(setq elem (car ext-alist))
(setq ext-alist (cdr ext-alist))
(setq orig (nth 0 elem))
(setq wlr (nth 1 elem))
(setq map (nth 2 elem))
(if switch
(substitute-key-definition wlr orig (or map gmap))
(substitute-key-definition orig wlr (or map gmap)))
)))
;;; **************************************************************************
(defun whole-line-or-region-restore-keys ()
"Restore keys according to `whole-line-or-region-extensions-alist'."
(whole-line-or-region-bind-keys t))
;;; **************************************************************************
(defun whole-line-or-region-append-to-list (list-var element)
"Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
The test for presence of ELEMENT is done with `equal'.
If ELEMENT is added, it is added at the beginning of the list,
unless the optional argument APPEND is non-nil, in which case
ELEMENT is added at the end.
If you want to use `whole-line-or-region-append-to-list' on a variable that is not defined
until a certain package is loaded, you should put the call to `whole-line-or-region-append-to-list'
into a hook function that will be run only after loading the package.
`eval-after-load' provides one way to do this. In some cases
other hooks, such as major mode hooks, can do the job."
(set list-var
(append (symbol-value list-var) (if (listp element) element (list element)))
))
;;; **************************************************************************
;;; ***** we're done
;;; **************************************************************************
(provide 'whole-line-or-region)
(run-hooks 'whole-line-or-region-load-hook)
;;; whole-line-or-region.el ends here
;;; **************************************************************************
;;;; ***** EOF ***** EOF ***** EOF ***** EOF ***** EOF *************