public
Description: My configuration files for various applications
Homepage: http://mina86.com/
Clone URL: git://github.com/mina86/dot-files.git
mina86 (author)
Fri Oct 16 02:33:17 -0700 2009
commit  f20802d27bfc52da3bc4038a3042d3ccb058f875
tree    ee7f0243169d09a22185614288afec6b9cd6c5aa
parent  ba198f5843b077cbeff5ad542b8cccd33dc706d2
dot-files / risc-mode.el
100644 631 lines (555 sloc) 23.219 kb
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
;; -*- mode: emacs-lisp; indent-tabs-mode: nil -*-
;;{{{ Header
;;
;; RISC Mode v. 0.3
;; $Id: risc-mode.el,v 1.4 2007/08/08 13:31:48 mina86 Exp $
;; Copyright (c) 2006 by Michal Nazarewicz (mina86/AT/mina86.com)
;;
;; This software is OSI Certified Open Source Software.
;; OSI Certified is a certification mark of the Open Source Initiative.
;;
;; 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 of the License, 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; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;;
;;}}}
;;{{{ Commentary
;;
;;{{{ Idea
;;
;; All actions which one may do in a text editor can be divided into
;; two groups: typing and doing other stuff. In EMACS it is trivial
;; to type as it's enought to type a character you want to put into
;; a buffer whereas 'other stuff' require key sequences some of which
;; are pretty long or hard to type. That's OK as long as you type
;; mostly but what if you need to kill a lot of lines and your finger
;; hurts of holding a control key?
;;
;; RISC Mode provides another mode in which a certain actions (other
;; then inserting a characters) are assigned to each letter. This way
;; you don't need to hold a control key to perform tasks such as
;; killing lines or words. You still need to hold shift key in some
;; situations but it's rather rare. ;)
;;
;; Personally I find RISC Mode very useful as I don't need to move my
;; hand to the parto of the keyboard with arrows as 'ijkl' works just
;; as good.
;;
;; Where did the name come from? CISC CPUs provide a lot of
;; instructions encoded in a variable length (posibly very long) bit
;; sequences. RISC CPUs provide a small set of commands encoded in
;; a fixed, short bit sequences. Now imagine that a bit is one key
;; stroke immidietly you see that EMACS is a "CISC editor" as it
;; provides a lot of commands with a variable length key bindings.
;; RISC Mode provides a short key bindings for only the basic editor
;; commands.
;;
;;}}}
;;{{{ Installatin
;;
;; Put 'risc-mode.el' somewhere `load' will find it and put the
;; fallowing lines to your '.emacs' file:
;;
;; (autoload 'risc-mode "risc-mode" "Toggles RISC Mode on or off" t)
;; (autoload 'risc-mode-toggle "risc-mode" "Toggles RISC Mode on or off" t)
;; (global-set-key "\C-c\C-c" 'risc-mode-toggle)
;; (global-set-key (kbd "<menu>") 'risc-mode-toggle)
;;
;; If you are used to using menu key for executing commands or set it
;; to do something else you may want to comment out the last line.
;;
;; I also added the fallowing to my .Xmodmap file:
;;
;; remove Lock = Caps_Lock
;; keysym Caps_Lock = Menu Help
;;
;; so it's enought to press Caps Lock, which is qutie easy to press,
;; to toggle RISC Mode.
;;
;;}}}
;;{{{ ModeLine
;;
;; When RISC Mode is enabled EMACS behaves completly different then
;; usually so a easy way to dystinguish whether it is on or off is
;; needed. Putting 'RISC' in ModeLine does not work as it is quit
;; small and easy to overlook. Because of that, when RISC Mode (Poor
;; RISC Mode) is enabled a background color of ModeLine is changed to
;; red (yellow). This is controlled by `risc-mode-modeline-bg',
;; `poor-risc-mode-modeline-bg' and `risc-mode-off-modeline-bg'
;; varaibles.
;;
;;}}}
;;{{{ Poor RISC Mode
;;
;; Poor RISC Mode is enabled by presing either Q or '. In this mode
;; EMACS behaves almost "normal". The only difference is that
;; pressing RET or ESC ESC turns RISC Mode on again (and Poor RISC
;; Mode off). This is ment to be an easy way to insert few words when
;; in RISC Mode.
;;
;;}}}
;;{{{ Key Bindings
;;
;; i j k l -- moves by one char/line in an obvious manner
;; I J K L -- moves by one word/paragraph in an obvious manner
;;
;; h a -- moves to the beginning of line [1]
;; ; e -- moves to the end of line [2]
;; A -- moves to the beginning of buffer
;; E -- moves to the end of buffer
;;
;; M-i M-k -- scrolls window down/up one line w/o moving the cursor
;; n p -- scrolls one screen down/up [3]
;; / -- recenteres window [4]
;;
;; N P -- moves cursor to the next/previous window in a frame
;; H : -- changes current buffer to the previous/next
;;
;; x -- deletes char
;; X -- deletes char backward
;; D -- kills line
;;
;; di dk -- kills previous/next line
;; dj dl -- deletes previous/next char
;; dI dK -- kills previous/next paragraph
;; dJ dL -- kills previous/next word
;;
;; dh da -- kills characters from the beginning of line
;; d; de -- kills characters till the end of line
;; dd -- kills whole line
;;
;; q -- inserts the next typed character
;; Q ' -- enables Poor RISC Mode
;; dq -- toogles overwrite mode
;;
;; o O -- inserts new line before the current (and turns Poor RISC Mode)
;; m M -- inserts new line after the current (and turns Poor RISC Mode)
;;
;; t -- transposes chars
;; T -- transposes words
;; dt -- transposes lines
;;
;; v -- sets mark
;; dv -- kills selection
;; VV -- exchanges point and mark [5]
;;
;; b -- reads pressed char and saves bookmark [6]
;; B -- reads pressed char and jumps to saved bookmark [6]
;; db -- reads pressed char and deletes saved bookmark [6]
;; SPC -- alias of "b "
;; C-SPC -- alias of "B "
;;
;; G -- if defining a macro stops defining;
;; else if defined macro exists calls it;
;; else starts defining a macro [7]
;; dG -- if defining a macro inserts counter, deletes macro otehrwise
;; . -- repeats last command
;;
;; s S -- isearches forward/backward
;; f F -- isearches forward/backward regexp
;; w W -- (query) replaces a string
;; r R -- (query) replaces a regexp
;;
;; g -- `keyboard-quit'
;; u -- `universal-argument'
;; y -- `yank'
;; Y -- `yank' or `yank-pop' if last command was `yank'
;; z -- undos
;; Z -- undos with limit to changes within the current region
;; ? -- whatever M-/ was bound to.
;;
;; c -- an alias to C-x
;; cc -- disables RISC Mode
;; C -- reserved for user
;;
;; *** Notes
;;
;; [1] "h" and "a" are set to the same thing "C-a" was set when RISC
;; Mode was loaded.
;; [2] ";" and "e" are set to the same thinf "C-e" was set when RISC
;; Mode was loaded.
;; [3] "n" and "p" are set to the same thing "C-v" and "M-v" was set
;; when RISC Mode was loaded.
;; [4] "/" is set to the same thing "C-l" was set when RISC Mode was
;; loaded.
;; [5] "V" is ment to be a prefix character so in the future new
;; "V<x>" bindings may be added.
;; [6] Any key other then SPC is used verbatim as a bookmark name.
;; SPC is treated specialy and evaluated either to last bookmark
;; name used or buffer name if no bookmark was set yet.
;; [7] Note that "dGG" will always start a new macro even if one is
;; already defined.
;;
;;}}}
;;
;;}}}
;;{{{ Variables
 
;; Toggle variables
(defcustom risc-mode nil
  "Non-nil if RISC Mode is enabled.
See the command `risc-mode' for a description of this minor-mode.
Setting this variable directly does not take effect; use either
\\[customize] or the function `risc-mode'."
  :set 'custom-set-minor-mode
  :initialize 'custom-initialize-default
  :group 'risc-mode
  :type 'boolean)
 
(defcustom poor-risc-mode nil
  "Non-nil if Poor RISC Mode is enabled.
See the command `risc-mode' for a description of this minor-mode.
Setting this variable directly does not take effect; use either
\\[customize] or the function `poor-risc-mode'."
  :set 'custom-set-minor-mode
  :initialize 'custom-initialize-default
  :group 'poor-risc-mode
  :type 'boolean)
 
 
; We need to disable RISC mode in minibuffer
(defvar risc-mode-map-enabled nil)
(defvar poor-risc-mode-map-enabled nil)
 
(add-hook 'minibuffer-setup-hook
          (lambda () (setq risc-mode-map-enabled nil
                           poor-risc-mode-map-enabled nil)))
 
(add-hook 'minibuffer-exit-hook
          (lambda () (setq risc-mode-map-enabled risc-mode
                           poor-risc-mode-map-enabled poor-risc-mode)))
 
 
;; Keymaps
(defvar risc-mode-map (make-keymap) "Keymap for `risc-mode'.")
(defvar poor-risc-mode-map (make-keymap) "Keymap for `poor-risc-mode'.")
 
;; Macro for easier key setting
(defmacro risc-set-key (key func) "Defines a key in `risc-mode-map'."
  (list 'define-key 'risc-mode-map key func))
 
;; Poor RISC mode
(define-key poor-risc-mode-map "\n" 'risc-mode)
(define-key poor-risc-mode-map "\e\e" 'risc-mode)
(define-key poor-risc-mode-map (kbd "<ret>") 'risc-mode)
(define-key poor-risc-mode-map (kbd "<return>") 'risc-mode)
 
 
;; Modeline backgrounds
(defcustom risc-mode-modeline-bg "red"
  "`modeline' background when `risc-mode' is enabled."
  :set 'custom-set-minor-mode
  :initialize 'custom-initialize-default
  :group 'risc-mode
  :type 'color)
 
(defcustom poor-risc-mode-modeline-bg "darkgreen"
  "`modeline' background when `poor-risc-mode' is enabled."
  :set 'custom-set-minor-mode
  :initialize 'custom-initialize-default
  :group 'risc-mode
  :type 'color)
 
(defcustom risc-mode-off-modeline-bg "blue"
  "`modeline' background when `risc-mode' is disabled."
  :set 'custom-set-minor-mode
  :initialize 'custom-initialize-default
  :group 'risc-mode
  :type 'color)
 
 
;; Add minor modes
(add-minor-mode 'risc-mode " RISC")
(add-minor-mode 'poor-risc-mode " risc")
(setq minor-mode-map-alist
      (cons (cons 'risc-mode-map-enabled risc-mode-map)
            (assq-delete-all 'risc-mode-map-enabled minor-mode-map-alist)))
;; poor-risc-mode-map is added by risc-mode
 
;;}}}
;;{{{ Functions
 
;; RISC Mode
(defun risc-mode (&optional arg msg)
  "Toggle RISC Mode and Poor RISC Mode on or off.
Interactively, with no prefix argument, toggle the RISC Mode.
With universal prefix ARG turn RISC Mode on.
With zero or negative ARG turn RISC and Poor Risc Modes off.
With `arg' being \"p\" turns Poor RISC Mode on.
Only one of the modes RISC Mode and Poor RISC Mode
can be enabled at the same time.
 
If `msg' is no-nill prints message in echo area even if called
noninteractively unless it is -1 in which case the message won't
be displayed.
 
RISC Mode Povides short, 1- and 2-character long key bindings for
many common operations. This way it is much easier to move
around the text and transform it's content then when the mode is
disabled however it is much harder to insert any text.
 
Poor RISC Mode adds a key bindings for RET and ESC ESC which turn
RISC Mode on as well as binding for C-c C-c which turns Poor RISC
Mode off (and does not enable RISC Mode)."
  (interactive "P")
  (if (eq arg 'toggle) (setq arg nil))
  (let ((prm poor-risc-mode) (rm risc-mode))
 
    ;; Turn modes on/off
    (setq risc-mode (if (not arg) (not risc-mode)
                        (and (not (equal arg "p"))
                             (> (prefix-numeric-value arg) 0))))
    (setq poor-risc-mode (equal arg "p"))
    (setq risc-mode-map-enabled risc-mode
          poor-risc-mode-map-enabled poor-risc-mode)
 
    ;; Set modeline background
    (set-face-background
     'modeline (cond (risc-mode risc-mode-modeline-bg)
                     (poor-risc-mode poor-risc-mode-modeline-bg)
                     (t risc-mode-off-modeline-bg)))
 
    ;; Move Poor RISC Mode keymap at the beginnig
    (unless (or (not poor-risc-mode)
                (eq (caar minor-mode-map-alist) 'poor-risc-mode-map-enabled))
      (setq minor-mode-map-alist
            (cons (cons 'poor-risc-mode-map-enabled poor-risc-mode-map)
                  (assq-delete-all 'poor-risc-mode-map-enabled
                                   minor-mode-map-alist))))
 
    ;; 'c' as alias of C-x
    (unless (or (not risc-mode) rm)
      (risc-set-key "c" (copy-keymap (lookup-key (current-global-map) "\C-x")))
      (risc-set-key "cc" 'risc-mode-toggle)
      (risc-set-key "c\C-c" (lambda () (interactive) (error "Use C-x C-c"))))
 
    ;; On/off hooks
    (if (and rm (not risc-mode))
        (run-hooks 'risc-mode-hook 'risc-mode-off-hook))
    (if (and prm (not poor-risc-mode))
        (run-hooks 'poor-risc-mode-hook 'poor-risc-mode-off-hook))
    (if (and (not rm ) risc-mode)
        (run-hooks 'risc-mode-hook 'risc-mode-on-hook))
    (if (and (not prm) poor-risc-mode)
        (run-hooks 'poor-risc-mode-hook 'poor-risc-mode-on-hook))
 
    ;; Customize
    (unless (not (called-interactively-p))
      (customize-mark-as-set risc-mode)
      (customize-mark-as-set poor-risc-mode))
 
    ;; Message
    (if (and (not (current-message)) (not (eq msg -1))
             (or msg (called-interactively-p)))
        (cond
         (risc-mode (message "RISC Mode enabled"))
         (poor-risc-mode (message "Poor RISC Mode enabled"))
         (rm (message "RISC Mode disabled"))
         (prm (message "Poor RISC Mode disabled"))))
 
    ;; Final stuff
    (force-mode-line-update)
    risc-mode))
 
 
;; Poor RISC Mode
(defun poor-risc-mode (&optional arg msg)
  "Toggle Poor RISC Mode and RISC Mode on or off.
Interactively, with no prefix argument, toggle the Poor RISC Mode and
sets RISC Mode to the state opposite to Poor RISC mode.
With universal prefix ARG turn Poor RISC Mode on and RISC Mode off.
With zero or negative ARG turn Poor RISC Mode and RISC mode off.
Fore more information see `risc-mode'.
 
If `msg' is no-nill prints message in echo area even if called
noninteractively unless it is -1 in which case the message won't
be displayed."
  (interactive (list (or current-prefix-arg nil) nil))
  (if (eq arg 'toggle) (setq arg nil))
  (setq msg (or msg (called-interactively-p)))
  (cond
   ((and (eq arg nil) (not poor-risc-mode)) (risc-mode "p" msg))
   ((and (eq arg nil) poor-risc-mode ) (risc-mode 1 msg))
   ((> (prefix-numeric-value arg) 0) (risc-mode "p" msg))
   (t (risc-mode 0 msg)))
  poor-risc-mode)
 
 
;; Toggles RISC Mode taking Poor RISC mode into account
(defun risc-mode-toggle (&optional arg msg)
  "Toggle Poor RISC Mode and RISC Mode on or off.
Interactively, with no prefix argument, disables RISC and Poor RISC
mode if any of those modes is enabled otherwise enables RISC Mode.
With universal prefix ARG turn RISC Mode on.
With zero or negative ARG turn RISC Mode and Poor RISC mode off.
Fore more information see `risc-mode'.
 
If `msg' is no-nill prints message in echo area even if called
noninteractively unless it is -1 in which case the message won't
be displayed."
  (interactive (list (or current-prefix-arg nil) nil))
  (if (eq arg 'toggle) (setq arg nil))
  (risc-mode (if arg arg (if (or risc-mode poor-risc-mode) -1 1))
             (or msg (called-interactively-p))))
 
;;}}}
;;{{{ Moving
 
;; Basic movement
(risc-set-key "l" 'forward-char)
(risc-set-key "L" 'forward-word)
(risc-set-key "j" 'backward-char)
(risc-set-key "J" 'backward-word)
(risc-set-key "k" 'next-line)
(risc-set-key "K" 'forward-paragraph)
(risc-set-key "i" 'previous-line)
(risc-set-key "I" 'backward-paragraph)
 
;; Home & End
(risc-set-key "h" (lookup-key (current-global-map) "\C-a"))
(risc-set-key "a" (lookup-key (current-global-map) "\C-a"))
(risc-set-key ";" (lookup-key (current-global-map) "\C-e"))
(risc-set-key "e" (lookup-key (current-global-map) "\C-e"))
(risc-set-key "A" 'beginning-of-buffer)
(risc-set-key "E" 'end-of-buffer)
 
;; Scroll screen and page up/down
(risc-set-key "\ei" (lambda () (interactive) (scroll-down 1)))
(risc-set-key "\ek" (lambda () (interactive) (scroll-up 1)))
(risc-set-key "p" (lookup-key (current-global-map) "\ev"))
(risc-set-key "n" (lookup-key (current-global-map) "\C-v"))
 
;; Window/frame/buffer manpipulation
(risc-set-key "N" 'other-window)
(risc-set-key "P" (lambda (arg) (interactive "p") (other-window (- 0 arg))))
(risc-set-key "/" (lookup-key (current-global-map) "\C-l"))
(risc-set-key "H" 'previous-buffer)
(risc-set-key ":" 'next-buffer)
 
;;}}}
;;{{{ Modification
 
;; Delete
(risc-set-key "x" 'delete-char)
(risc-set-key "X" 'backward-delete-char)
 
(risc-set-key "dl" 'delete-char)
(risc-set-key "dj" 'backward-delete-char)
(risc-set-key "dL" 'kill-word)
(risc-set-key "dJ" 'backward-kill-word)
 
(defun kill-line-backwards (&optional arg)
  "Kill characters backwards till the beginning of the current line;
if no nonblanks there, kill thru newline.
With prefix argument, kill that many lines from point.
Negative arguments kill lines forward.
With zero argument, kills the text after point on the current line.
 
When calling from a program, nil means \"no arg\",
a number counts as a prefix arg.
 
To kill a whole line, when point is not at the beginning, type \
\\[end-of-line] \\[kill-line-backwards] \\[kill-line-backwards].
 
If `kill-whole-line' is non-nil, then this command kills the whole line
plus previous line's terminating newline, when used at the end of a line
with no argument. As a consequence, you can always kill a whole line
by typing \\[end-of-line] \\[kill-line-backwards].
 
If you want to append the killed line to the last killed text,
use \\[append-next-kill] before \\[kill-line-backwards].
 
If the buffer is read-only, Emacs will beep and refrain from deleting
the line, but put the line in the kill ring anyway. This means that
you can use this command to copy text from a read-only buffer.
\(If the variable `kill-read-only-ok' is non-nil, then this won't
even beep.)"
  (interactive "P")
  (kill-region
   (point)
   (progn
     (if arg
         (if (= arg 0)
             (end-of-line)
           (forward-visible-line (- 0 (prefix-numeric-value arg))))
       (if (bobp) (signal 'beginning-of-buffer nil))
       (if (eobp) (signal 'end-of-buffer nil))
       (skip-chars-backward " \t")
       (if (or kill-whole-line (bolp))
           (progn (forward-visible-line -1) (end-of-line))
         (forward-visible-line 0)))
     (point))))
 
 
(risc-set-key "dk" 'kill-line)
(risc-set-key "D" 'kill-line)
(risc-set-key "di" 'kill-line-backwards)
(risc-set-key "dI"
  (lambda (arg) (interactive "p")
    (kill-region (point) (save-excursion (backward-paragraph arg) (point)))))
(risc-set-key "dK"
  (lambda (arg) (interactive "p")
    (kill-region (point) (save-excursion (forward-paragraph arg) (point)))))
 
(risc-set-key "dd" 'kill-whole-line)
 
(risc-set-key "dh" "u0dk")
(risc-set-key "d;" "u0di")
(risc-set-key "da" "u0dk")
(risc-set-key "de" "u0di")
 
;; Insert
(risc-set-key "q" (lambda (arg) (interactive "*p")
                       (setq last-command-char (read-char))
                       (self-insert-command arg)))
(risc-set-key "Q" 'poor-risc-mode)
(risc-set-key "'" 'poor-risc-mode)
(risc-set-key "dq" 'overwrite-mode)
 
;; Insert line
(risc-set-key "o"
  (lambda () (interactive) (beginning-of-line)(call-interactively 'open-line)))
(risc-set-key "O"
  (lambda () (interactive) (beginning-of-line)(call-interactively 'open-line)
    (poor-risc-mode)))
 
(risc-set-key "m"
  (lambda () (interactive) (end-of-line) (call-interactively 'newline)))
(risc-set-key "M"
  (lambda () (interactive) (end-of-line) (call-interactively 'newline)
    (poor-risc-mode)))
 
;; Transpose
(risc-set-key "t" 'transpose-chars)
(risc-set-key "T" 'transpose-words)
(risc-set-key "dt" 'transpose-lines)
 
;; Selecting
(risc-set-key "v" 'set-mark-command)
(risc-set-key "dv" 'kill-region)
(risc-set-key "VV" 'exchange-point-and-mark)
 
;;}}}
;;{{{ Bookmarks
 
(require 'bookmark)
 
(defun risc-bookmark-read-name ()
  (let ((char (read-char)))
    (if (eq char 32)
        (or bookmark-current-bookmark (bookmark-buffer-name))
      (format "%c" char))))
; (if (and enable-multibyte-characters
; (>=
; (unibyte-char-to-multibyte char)
; char)))))))
 
(risc-set-key "b" (lambda (a) (interactive "p")
                      (bookmark-set (risc-bookmark-read-name) a)))
(risc-set-key "B" (lambda () (interactive)
                      (bookmark-jump (risc-bookmark-read-name))))
(risc-set-key "db" (lambda () (interactive)
                      (bookmark-delete (risc-bookmark-read-name))))
 
(risc-set-key " " "b ")
(risc-set-key (kbd "C-SPC") "B ")
 
;;}}}
;;{{{ Macros
 
(defun risc-macro (arg)
  "If `defining-kbd-macro' function will `kmacro-end-macro'
otherwise if no macro is defined will `kmacro-start-macro' otherwise
will `call-last-kbd-macro'."
  (interactive "P")
  (if defining-kbd-macro (if arg (end-kbd-macro arg) (end-kbd-macro))
    (if last-kbd-macro (call-last-kbd-macro arg) (start-kbd-macro arg))))
 
(defun risc-macro-delete-or-insert-counter (a)
  "If `defining-kbd-macro' or `executing-kbd-macro' will
`kmacro-insert-counter' otherwise will set `last-kbd-macro' to
nil."
  (interactive "P")
  (if (or defining-kbd-macro executing-kbd-macro)
      (kmacro-insert-counter 1) (setq last-kbd-macro ())))
 
(risc-set-key "G" 'risc-macro)
(risc-set-key "dG" 'risc-macro-delete-or-insert-counter)
 
(risc-set-key "." 'repeat)
 
;;}}}
;;{{{ Other
 
;; Search and replace
(risc-set-key "s" 'isearch-forward)
(risc-set-key "S" 'isearch-backward)
(risc-set-key "f" 'isearch-forward-regexp)
(risc-set-key "F" 'isearch-backward-regexp)
(risc-set-key "w" 'replace-string)
(risc-set-key "W" 'query-replace)
(risc-set-key "r" 'replace-regexp)
(risc-set-key "R" 'query-replace-regexp)
 
;; Misc
(risc-set-key "g" 'keyboard-quit)
(risc-set-key "u" 'universal-argument)
(risc-set-key "y" 'yank)
(risc-set-key "Y" (lambda () (interactive)
                       (call-interactively
                        (if (eq last-command 'yank) 'yank-pop 'yank))))
(risc-set-key "z" 'undo)
(risc-set-key "Z" "uz")
(risc-set-key (kbd "?") (lookup-key (current-global-map) "\M-/"))
 
 
;; Add "u" to universal universal-argument-map
(defun risc-universal-argument-more ()
  "Calls `universal-argument-more' if in `risc-mode' or
`universal-argument-other-key' otherwise."
  (interactive)
  (call-interactively (if risc-mode 'universal-argument-more
                        'universal-argument-other-key)))
 
(unless (assq 117 universal-argument-map)
  (setcdr universal-argument-map
          (cons
           (cons 117 'risc-universal-argument-more)
           (cdr universal-argument-map))))
 
;;}}}