comparison lisp/emulation/cua-base.el @ 64311:d1bb70278f2a

(cua--pre-command-handler-1, cua--pre-command-handler) (cua--post-command-handler-1, cua--post-command-handler): Split in two. Check (buffer local) value of cua-mode. (cua-selection-mode): New command.
author Kim F. Storm <storm@cua.dk>
date Thu, 14 Jul 2005 08:27:30 +0000
parents 18a818a2ee7c
children 95c2d98fdeb1
comparison
equal deleted inserted replaced
64310:5ac4e912d629 64311:d1bb70278f2a
1058 (setq default-cursor-type type)))) 1058 (setq default-cursor-type type))))
1059 1059
1060 1060
1061 ;;; Pre-command hook 1061 ;;; Pre-command hook
1062 1062
1063 (defun cua--pre-command-handler-1 ()
1064 (let ((movement (eq (get this-command 'CUA) 'move)))
1065
1066 ;; Cancel prefix key timeout if user enters another key.
1067 (when cua--prefix-override-timer
1068 (if (timerp cua--prefix-override-timer)
1069 (cancel-timer cua--prefix-override-timer))
1070 (setq cua--prefix-override-timer nil))
1071
1072 ;; Handle shifted cursor keys and other movement commands.
1073 ;; If region is not active, region is activated if key is shifted.
1074 ;; If region is active, region is cancelled if key is unshifted (and region not started with C-SPC).
1075 ;; If rectangle is active, expand rectangle in specified direction and ignore the movement.
1076 (if movement
1077 (cond
1078 ((if window-system
1079 (memq 'shift (event-modifiers
1080 (aref (this-single-command-raw-keys) 0)))
1081 (or
1082 (memq 'shift (event-modifiers
1083 (aref (this-single-command-keys) 0)))
1084 ;; See if raw escape sequence maps to a shifted event, e.g. S-up or C-S-home.
1085 (and (boundp 'function-key-map)
1086 function-key-map
1087 (let ((ev (lookup-key function-key-map
1088 (this-single-command-raw-keys))))
1089 (and (vector ev)
1090 (symbolp (setq ev (aref ev 0)))
1091 (string-match "S-" (symbol-name ev)))))))
1092 (unless mark-active
1093 (push-mark-command nil t))
1094 (setq cua--last-region-shifted t)
1095 (setq cua--explicit-region-start nil))
1096 ((or cua--explicit-region-start cua--rectangle)
1097 (unless mark-active
1098 (push-mark-command nil nil)))
1099 (t
1100 ;; If we set mark-active to nil here, the region highlight will not be
1101 ;; removed by the direct_output_ commands.
1102 (setq deactivate-mark t)))
1103
1104 ;; Handle delete-selection property on other commands
1105 (if (and mark-active (not deactivate-mark))
1106 (let* ((ds (or (get this-command 'delete-selection)
1107 (get this-command 'pending-delete)))
1108 (nc (cond
1109 ((not ds) nil)
1110 ((eq ds 'yank)
1111 'cua-paste)
1112 ((eq ds 'kill)
1113 (if cua--rectangle
1114 'cua-copy-rectangle
1115 'cua-copy-region))
1116 ((eq ds 'supersede)
1117 (if cua--rectangle
1118 'cua-delete-rectangle
1119 'cua-delete-region))
1120 (t
1121 (if cua--rectangle
1122 'cua-delete-rectangle ;; replace?
1123 'cua-replace-region)))))
1124 (if nc
1125 (setq this-original-command this-command
1126 this-command nc)))))
1127
1128 ;; Detect extension of rectangles by mouse or other movement
1129 (setq cua--buffer-and-point-before-command
1130 (if cua--rectangle (cons (current-buffer) (point))))))
1131
1063 (defun cua--pre-command-handler () 1132 (defun cua--pre-command-handler ()
1064 (condition-case nil 1133 (when cua-mode
1065 (let ((movement (eq (get this-command 'CUA) 'move))) 1134 (condition-case nil
1066 1135 (cua--pre-command-handler-1)
1067 ;; Cancel prefix key timeout if user enters another key. 1136 (error nil))))
1068 (when cua--prefix-override-timer
1069 (if (timerp cua--prefix-override-timer)
1070 (cancel-timer cua--prefix-override-timer))
1071 (setq cua--prefix-override-timer nil))
1072
1073 ;; Handle shifted cursor keys and other movement commands.
1074 ;; If region is not active, region is activated if key is shifted.
1075 ;; If region is active, region is cancelled if key is unshifted (and region not started with C-SPC).
1076 ;; If rectangle is active, expand rectangle in specified direction and ignore the movement.
1077 (if movement
1078 (cond
1079 ((if window-system
1080 (memq 'shift (event-modifiers
1081 (aref (this-single-command-raw-keys) 0)))
1082 (or
1083 (memq 'shift (event-modifiers
1084 (aref (this-single-command-keys) 0)))
1085 ;; See if raw escape sequence maps to a shifted event, e.g. S-up or C-S-home.
1086 (and (boundp 'function-key-map)
1087 function-key-map
1088 (let ((ev (lookup-key function-key-map
1089 (this-single-command-raw-keys))))
1090 (and (vector ev)
1091 (symbolp (setq ev (aref ev 0)))
1092 (string-match "S-" (symbol-name ev)))))))
1093 (unless mark-active
1094 (push-mark-command nil t))
1095 (setq cua--last-region-shifted t)
1096 (setq cua--explicit-region-start nil))
1097 ((or cua--explicit-region-start cua--rectangle)
1098 (unless mark-active
1099 (push-mark-command nil nil)))
1100 (t
1101 ;; If we set mark-active to nil here, the region highlight will not be
1102 ;; removed by the direct_output_ commands.
1103 (setq deactivate-mark t)))
1104
1105 ;; Handle delete-selection property on other commands
1106 (if (and mark-active (not deactivate-mark))
1107 (let* ((ds (or (get this-command 'delete-selection)
1108 (get this-command 'pending-delete)))
1109 (nc (cond
1110 ((not ds) nil)
1111 ((eq ds 'yank)
1112 'cua-paste)
1113 ((eq ds 'kill)
1114 (if cua--rectangle
1115 'cua-copy-rectangle
1116 'cua-copy-region))
1117 ((eq ds 'supersede)
1118 (if cua--rectangle
1119 'cua-delete-rectangle
1120 'cua-delete-region))
1121 (t
1122 (if cua--rectangle
1123 'cua-delete-rectangle ;; replace?
1124 'cua-replace-region)))))
1125 (if nc
1126 (setq this-original-command this-command
1127 this-command nc)))))
1128
1129 ;; Detect extension of rectangles by mouse or other movement
1130 (setq cua--buffer-and-point-before-command
1131 (if cua--rectangle (cons (current-buffer) (point))))
1132 )
1133 (error nil)))
1134 1137
1135 ;;; Post-command hook 1138 ;;; Post-command hook
1136 1139
1140 (defun cua--post-command-handler-1 ()
1141 (when cua--global-mark-active
1142 (cua--global-mark-post-command))
1143 (when (fboundp 'cua--rectangle-post-command)
1144 (cua--rectangle-post-command))
1145 (setq cua--buffer-and-point-before-command nil)
1146 (if (or (not mark-active) deactivate-mark)
1147 (setq cua--explicit-region-start nil))
1148
1149 ;; Debugging
1150 (if cua--debug
1151 (cond
1152 (cua--rectangle (cua--rectangle-assert))
1153 (mark-active (message "Mark=%d Point=%d Expl=%s"
1154 (mark t) (point) cua--explicit-region-start))))
1155
1156 ;; Disable transient-mark-mode if rectangle active in current buffer.
1157 (if (not (window-minibuffer-p (selected-window)))
1158 (setq transient-mark-mode (and (not cua--rectangle)
1159 (if cua-highlight-region-shift-only
1160 (not cua--explicit-region-start)
1161 t))))
1162 (if cua-enable-cursor-indications
1163 (cua--update-indications))
1164
1165 (cua--select-keymaps))
1166
1137 (defun cua--post-command-handler () 1167 (defun cua--post-command-handler ()
1138 (condition-case nil 1168 (when cua-mode
1139 (progn 1169 (condition-case nil
1140 (when cua--global-mark-active 1170 (cua--post-command-handler-1)
1141 (cua--global-mark-post-command)) 1171 (error nil))))
1142 (when (fboundp 'cua--rectangle-post-command)
1143 (cua--rectangle-post-command))
1144 (setq cua--buffer-and-point-before-command nil)
1145 (if (or (not mark-active) deactivate-mark)
1146 (setq cua--explicit-region-start nil))
1147
1148 ;; Debugging
1149 (if cua--debug
1150 (cond
1151 (cua--rectangle (cua--rectangle-assert))
1152 (mark-active (message "Mark=%d Point=%d Expl=%s"
1153 (mark t) (point) cua--explicit-region-start))))
1154
1155 ;; Disable transient-mark-mode if rectangle active in current buffer.
1156 (if (not (window-minibuffer-p (selected-window)))
1157 (setq transient-mark-mode (and (not cua--rectangle)
1158 (if cua-highlight-region-shift-only
1159 (not cua--explicit-region-start)
1160 t))))
1161 (if cua-enable-cursor-indications
1162 (cua--update-indications))
1163
1164 (cua--select-keymaps)
1165 )
1166
1167 (error nil)))
1168 1172
1169 1173
1170 ;;; Keymaps 1174 ;;; Keymaps
1171 1175
1172 (defun cua--M/H-key (map key fct) 1176 (defun cua--M/H-key (map key fct)
1391 (if (and (nth 1 cua--saved-state) (nth 2 cua--saved-state)) " and" "") 1395 (if (and (nth 1 cua--saved-state) (nth 2 cua--saved-state)) " and" "")
1392 (if (nth 2 cua--saved-state) " PC-Selection" "") 1396 (if (nth 2 cua--saved-state) " PC-Selection" "")
1393 (if (or (nth 1 cua--saved-state) (nth 2 cua--saved-state)) " enabled" ""))) 1397 (if (or (nth 1 cua--saved-state) (nth 2 cua--saved-state)) " enabled" "")))
1394 (setq cua--saved-state nil)))) 1398 (setq cua--saved-state nil))))
1395 1399
1400
1401 ;;;###autoload
1402 (defun cua-selection-mode (arg)
1403 "Enable CUA selection mode without the C-z/C-x/C-c/C-v bindings."
1404 (interactive "P")
1405 (setq-default cua-enable-cua-keys nil)
1406 (cua-mode arg))
1407
1408
1396 (defun cua-debug () 1409 (defun cua-debug ()
1397 "Toggle CUA debugging." 1410 "Toggle CUA debugging."
1398 (interactive) 1411 (interactive)
1399 (setq cua--debug (not cua--debug))) 1412 (setq cua--debug (not cua--debug)))
1400 1413