shift_mark.el
1 ; emacs "shift-mark" functionality 2 ; 3 ; Allows you to mark a region by holding down the Shift modifier key 4 ; and moving the cursor. 5 ; Source: http://www.cs.ucsb.edu/~matz/study/EmacsShiftMark.html 6 ; 7 ; written by matz"a"cs.ucsb.edu, March 10th, 1998 8 9 (defun shift-mark (cmd) 10 "Expands marked region to the point (position of cursor) after executing 11 command 'cmd'. If no region is marked, we mark one first." 12 (interactive "_a") 13 (if (not (region-active-p)) 14 (progn (set-mark-command nil) 15 (command-execute cmd)) 16 (command-execute cmd) 17 )) 18 19 (defun shift-mark-forward-char () 20 (interactive) 21 (shift-mark 'forward-char) 22 ) 23 24 (defun shift-mark-backward-char () 25 (interactive) 26 (shift-mark 'backward-char) 27 ) 28 29 (defun shift-mark-forward-word () 30 (interactive) 31 (shift-mark 'forward-word) 32 ) 33 34 (defun shift-mark-backward-word () 35 (interactive) 36 (shift-mark 'backward-word) 37 ) 38 39 (defun shift-mark-forward-paragraph () 40 (interactive) 41 (shift-mark 'forward-paragraph) 42 ) 43 44 (defun shift-mark-backward-paragraph () 45 (interactive) 46 (shift-mark 'backward-paragraph) 47 ) 48 49 (defun shift-mark-previous-line () 50 (interactive) 51 (shift-mark 'previous-line) 52 ) 53 54 (defun shift-mark-next-line () 55 (interactive) 56 (shift-mark 'next-line) 57 ) 58 59 (defun backspace-delete-marked-region () 60 (interactive) 61 ; (zmacs-region-stays t) 62 (if (region-active-p) 63 (kill-region (mark) (point)) 64 (delete-backward-char 1) 65 ) 66 ) 67 68 (global-set-key '(shift right) 'shift-mark-forward-char) 69 (global-set-key '(shift left) 'shift-mark-backward-char) 70 (global-set-key '(shift up) 'shift-mark-previous-line) 71 (global-set-key '(shift down) 'shift-mark-next-line) 72 (global-set-key '(shift control right) 'shift-mark-forward-word) 73 (global-set-key '(shift control left) 'shift-mark-backward-word) 74 (global-set-key '(shift control up) 'shift-mark-backward-paragraph) 75 (global-set-key '(shift control down) 'shift-mark-forward-paragraph) 76 (global-set-key '(shift backspace) 'backspace-delete-marked-region) 77 (global-set-key '(control backspace) 'backspace-delete-marked-region) 78 (global-set-key '(shift control backspace) 'backspace-delete-marked-region) 79 (global-set-key '(del) 'backspace-delete-marked-region) 80 81 (global-set-key '(control left) 'backward-word) 82 (global-set-key '(control right) 'forward-word) 83 (global-set-key '(control up) 'backward-paragraph) 84 (global-set-key '(control down) 'forward-paragraph) 85 (global-set-key '(f27) 'beginning-of-line) ;HOME 86 (global-set-key '(f33) 'end-of-line) ;END