aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-10-22 08:43:54 -0400
committerStefan Monnier2012-10-22 08:43:54 -0400
commitc77d37e227560d8ab87b475acef74bf20b54750e (patch)
tree6f549b6b304dbd90bab331497e34358231068532
parentb1d39ccce419eeec83a4bc723f6c9daf4ffb2be4 (diff)
downloademacs-c77d37e227560d8ab87b475acef74bf20b54750e.tar.gz
emacs-c77d37e227560d8ab87b475acef74bf20b54750e.zip
Rework the last delsel/electric fix.
* lisp/delsel.el (delete-selection-helper): Use a function instead of a hook. (delete-selection-pre-hook): Use use-region-p. (delete-selection-self-insert-function): Remove. (self-insert-command): Obey self-insert-uses-region-functions. (self-insert-iso): Revert to previous setting, since we don't actually know what that command does. (delete-selection-self-insert-hooks): Remove. * lisp/electric.el (electric-pair-delete-selection-self-insert-function): Rename to electric-pair-will-use-region, return a boolean. (electric-pair-mode): Adjust accordingly. Don't require delsel.
-rw-r--r--lisp/ChangeLog14
-rw-r--r--lisp/delsel.el55
-rw-r--r--lisp/electric.el17
3 files changed, 44 insertions, 42 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6edf13719ce..1b680eadc08 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
12012-10-22 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * electric.el (electric-pair-delete-selection-self-insert-function):
4 Rename to electric-pair-will-use-region, return a boolean.
5 (electric-pair-mode): Adjust accordingly. Don't require delsel.
6
7 * delsel.el (delete-selection-helper): Use a function instead of a hook.
8 (delete-selection-pre-hook): Use use-region-p.
9 (delete-selection-self-insert-function): Remove.
10 (self-insert-command): Obey self-insert-uses-region-functions.
11 (self-insert-iso): Revert to previous setting, since we don't actually
12 know what that command does.
13 (delete-selection-self-insert-hooks): Remove.
14
12012-10-22 Simon Law <sfllaw@sfllaw.ca> (tiny change) 152012-10-22 Simon Law <sfllaw@sfllaw.ca> (tiny change)
2 16
3 * delsel.el (delete-selection-helper): New function, extracted from 17 * delsel.el (delete-selection-helper): New function, extracted from
diff --git a/lisp/delsel.el b/lisp/delsel.el
index 09f58e086a2..2ed82676189 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -44,12 +44,12 @@
44;; `kill-region' is used on the selection, rather than 44;; `kill-region' is used on the selection, rather than
45;; `delete-region'. (Text selected with the mouse will typically 45;; `delete-region'. (Text selected with the mouse will typically
46;; be yankable anyhow.) 46;; be yankable anyhow.)
47;; non-nil 47;; t
48;; The normal case: delete the active region prior to executing 48;; The normal case: delete the active region prior to executing
49;; the command which will insert replacement text. 49;; the command which will insert replacement text.
50;; hooks 50;; <function>
51;; For commands which need to dynamically determine this behaviour. 51;; For commands which need to dynamically determine this behaviour.
52;; Each hook should return one of the above values or nil. 52;; The function should return one of the above values or nil.
53 53
54;;; Code: 54;;; Code:
55 55
@@ -82,23 +82,23 @@ If KILLP in not-nil, the active region is killed instead of deleted."
82 t) 82 t)
83 83
84(defun delete-selection-helper (type) 84(defun delete-selection-helper (type)
85 "Deletes selection according to TYPE: 85 "Delete selection according to TYPE:
86 'yank 86 `yank'
87 For commands which do a yank; ensures the region about to be 87 For commands which do a yank; ensures the region about to be
88 deleted isn't yanked. 88 deleted isn't yanked.
89 'supersede 89 `supersede'
90 Delete the active region and ignore the current command, 90 Delete the active region and ignore the current command,
91 i.e. the command will just delete the region. 91 i.e. the command will just delete the region.
92 'kill 92 `kill'
93 `kill-region' is used on the selection, rather than 93 `kill-region' is used on the selection, rather than
94 `delete-region'. (Text selected with the mouse will typically 94 `delete-region'. (Text selected with the mouse will typically
95 be yankable anyhow.) 95 be yankable anyhow.)
96 non-nil 96 t
97 The normal case: delete the active region prior to executing 97 The normal case: delete the active region prior to executing
98 the command which will insert replacement text. 98 the command which will insert replacement text.
99 hooks 99 FUNCTION
100 For commands which need to dynamically determine this behaviour. 100 For commands which need to dynamically determine this behaviour.
101 Each hook should return one of the above values or nil." 101 FUNCTION should take no argument and return one of the above values or nil."
102 (condition-case data 102 (condition-case data
103 (cond ((eq type 'kill) 103 (cond ((eq type 'kill)
104 (delete-active-region t)) 104 (delete-active-region t))
@@ -119,9 +119,7 @@ If KILLP in not-nil, the active region is killed instead of deleted."
119 (delete-active-region) 119 (delete-active-region)
120 (unless empty-region 120 (unless empty-region
121 (setq this-command 'ignore)))) 121 (setq this-command 'ignore))))
122 ((and (symbolp type) (not (booleanp type))) 122 ((functionp type) (delete-selection-helper (funcall type)))
123 (delete-selection-helper
124 (run-hook-with-args-until-success type)))
125 (type 123 (type
126 (delete-active-region) 124 (delete-active-region)
127 (if (and overwrite-mode 125 (if (and overwrite-mode
@@ -151,29 +149,22 @@ If KILLP in not-nil, the active region is killed instead of deleted."
151 (message "Text is read-only") (ding)))) 149 (message "Text is read-only") (ding))))
152 150
153(defun delete-selection-pre-hook () 151(defun delete-selection-pre-hook ()
154 "Normal hook run before commands that delete selections are executed. 152 "Function run before commands that delete selections are executed.
155Commands which will delete the selection need a 'delete-selection 153Commands which will delete the selection need a `delete-selection'
156property on their symbols; commands which insert text but don't 154property on their symbol; commands which insert text but don't
157have this property won't delete the selection. 155have this property won't delete the selection.
158 156See `delete-selection-helper'."
159See `delete-selection-helper'. 157 (when (and delete-selection-mode (use-region-p)
160"
161 (when (and delete-selection-mode transient-mark-mode mark-active
162 (not buffer-read-only)) 158 (not buffer-read-only))
163 (let ((type (and (symbolp this-command) 159 (delete-selection-helper (and (symbolp this-command)
164 (get this-command 'delete-selection)))) 160 (get this-command 'delete-selection)))))
165 (delete-selection-helper type))))
166
167(defun delete-selection-self-insert-function ()
168 t)
169 161
170(defvar delete-selection-self-insert-hooks 162(put 'self-insert-command 'delete-selection
171 '(delete-selection-self-insert-function) 163 (lambda ()
172 "Abnormal hook run before commands that insert characters. 164 (not (run-hook-with-args-until-success
173This hook should return a TYPE that `delete-selection-helper' understands.") 165 'self-insert-uses-region-functions))))
174 166
175(put 'self-insert-command 'delete-selection 'delete-selection-self-insert-hooks) 167(put 'self-insert-iso 'delete-selection t)
176(put 'self-insert-iso 'delete-selection 'delete-selection-self-insert-hooks)
177 168
178(put 'yank 'delete-selection 'yank) 169(put 'yank 'delete-selection 'yank)
179(put 'clipboard-yank 'delete-selection 'yank) 170(put 'clipboard-yank 'delete-selection 'yank)
diff --git a/lisp/electric.el b/lisp/electric.el
index e6fa1df914f..abf5a72ecaf 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -358,11 +358,9 @@ This can be convenient for people who find it easier to hit ) than C-f."
358 (eq (char-syntax (following-char)) ?w))) 358 (eq (char-syntax (following-char)) ?w)))
359 (save-excursion (insert closer)))))) 359 (save-excursion (insert closer))))))
360 360
361(defun electric-pair-delete-selection-self-insert-function () 361(defun electric-pair-will-use-region ()
362 (let ((syntax (electric-pair-syntax last-command-event))) 362 (and (use-region-p)
363 (if (and (memq syntax '(?\( ?\" ?\$)) (use-region-p)) 363 (memq (electric-pair-syntax last-command-event) '(?\( ?\" ?\$))))
364 'keep
365 t)))
366 364
367;;;###autoload 365;;;###autoload
368(define-minor-mode electric-pair-mode 366(define-minor-mode electric-pair-mode
@@ -380,15 +378,14 @@ See options `electric-pair-pairs' and `electric-pair-skip-self'."
380 :group 'electricity 378 :group 'electricity
381 (if electric-pair-mode 379 (if electric-pair-mode
382 (progn 380 (progn
383 (require 'delsel)
384 (add-hook 'post-self-insert-hook 381 (add-hook 'post-self-insert-hook
385 #'electric-pair-post-self-insert-function) 382 #'electric-pair-post-self-insert-function)
386 (add-hook 'delete-selection-self-insert-hooks 383 (add-hook 'self-insert-uses-region-functions
387 #'electric-pair-delete-selection-self-insert-function)) 384 #'electric-pair-will-use-region))
388 (remove-hook 'post-self-insert-hook 385 (remove-hook 'post-self-insert-hook
389 #'electric-pair-post-self-insert-function) 386 #'electric-pair-post-self-insert-function)
390 (remove-hook 'delete-selection-self-insert-hooks 387 (remove-hook 'self-insert-uses-region-functions
391 #'electric-pair-delete-selection-self-insert-function))) 388 #'electric-pair-will-use-region)))
392 389
393;; Automatically add newlines after/before/around some chars. 390;; Automatically add newlines after/before/around some chars.
394 391