emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r110617: Rework the last delsel/elect


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110617: Rework the last delsel/electric fix.
Date: Mon, 22 Oct 2012 08:43:54 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110617
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Mon 2012-10-22 08:43:54 -0400
message:
  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.
modified:
  lisp/ChangeLog
  lisp/delsel.el
  lisp/electric.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-10-22 03:15:44 +0000
+++ b/lisp/ChangeLog    2012-10-22 12:43:54 +0000
@@ -1,3 +1,17 @@
+2012-10-22  Stefan Monnier  <address@hidden>
+
+       * 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.
+
+       * 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.
+
 2012-10-22  Simon Law  <address@hidden>  (tiny change)
 
        * delsel.el (delete-selection-helper): New function, extracted from

=== modified file 'lisp/delsel.el'
--- a/lisp/delsel.el    2012-10-22 03:15:44 +0000
+++ b/lisp/delsel.el    2012-10-22 12:43:54 +0000
@@ -44,12 +44,12 @@
 ;;      `kill-region' is used on the selection, rather than
 ;;      `delete-region'.  (Text selected with the mouse will typically
 ;;      be yankable anyhow.)
-;;  non-nil
+;;  t
 ;;      The normal case: delete the active region prior to executing
 ;;      the command which will insert replacement text.
-;;  hooks
+;;  <function>
 ;;      For commands which need to dynamically determine this behaviour.
-;;      Each hook should return one of the above values or nil.
+;;      The function should return one of the above values or nil.
 
 ;;; Code:
 
@@ -82,23 +82,23 @@
   t)
 
 (defun delete-selection-helper (type)
-  "Deletes selection according to TYPE:
- 'yank
+  "Delete selection according to TYPE:
+ `yank'
      For commands which do a yank; ensures the region about to be
      deleted isn't yanked.
- 'supersede
+ `supersede'
      Delete the active region and ignore the current command,
      i.e. the command will just delete the region.
- 'kill
+ `kill'
      `kill-region' is used on the selection, rather than
      `delete-region'.  (Text selected with the mouse will typically
      be yankable anyhow.)
- non-nil
+ t
      The normal case: delete the active region prior to executing
      the command which will insert replacement text.
- hooks
+ FUNCTION
      For commands which need to dynamically determine this behaviour.
-     Each hook should return one of the above values or nil."
+     FUNCTION should take no argument and return one of the above values or 
nil."
   (condition-case data
       (cond ((eq type 'kill)
             (delete-active-region t))
@@ -119,9 +119,7 @@
               (delete-active-region)
               (unless empty-region
                 (setq this-command 'ignore))))
-           ((and (symbolp type) (not (booleanp type)))
-            (delete-selection-helper
-             (run-hook-with-args-until-success type)))
+           ((functionp type) (delete-selection-helper (funcall type)))
            (type
             (delete-active-region)
             (if (and overwrite-mode
@@ -151,29 +149,22 @@
      (message "Text is read-only") (ding))))
 
 (defun delete-selection-pre-hook ()
-  "Normal hook run before commands that delete selections are executed.
-Commands which will delete the selection need a 'delete-selection
-property on their symbols; commands which insert text but don't
+  "Function run before commands that delete selections are executed.
+Commands which will delete the selection need a `delete-selection'
+property on their symbol; commands which insert text but don't
 have this property won't delete the selection.
-
-See `delete-selection-helper'.
-"
-  (when (and delete-selection-mode transient-mark-mode mark-active
+See `delete-selection-helper'."
+  (when (and delete-selection-mode (use-region-p)
             (not buffer-read-only))
-    (let ((type (and (symbolp this-command)
-                    (get this-command 'delete-selection))))
-      (delete-selection-helper type))))
-
-(defun delete-selection-self-insert-function ()
-  t)
-
-(defvar delete-selection-self-insert-hooks
-  '(delete-selection-self-insert-function)
-  "Abnormal hook run before commands that insert characters.
-This hook should return a TYPE that `delete-selection-helper' understands.")
-
-(put 'self-insert-command 'delete-selection 
'delete-selection-self-insert-hooks)
-(put 'self-insert-iso 'delete-selection 'delete-selection-self-insert-hooks)
+    (delete-selection-helper (and (symbolp this-command)
+                                  (get this-command 'delete-selection)))))
+
+(put 'self-insert-command 'delete-selection
+     (lambda ()
+       (not (run-hook-with-args-until-success
+             'self-insert-uses-region-functions))))
+
+(put 'self-insert-iso 'delete-selection t)
 
 (put 'yank 'delete-selection 'yank)
 (put 'clipboard-yank 'delete-selection 'yank)

=== modified file 'lisp/electric.el'
--- a/lisp/electric.el  2012-10-22 03:15:44 +0000
+++ b/lisp/electric.el  2012-10-22 12:43:54 +0000
@@ -358,11 +358,9 @@
                (eq (char-syntax (following-char)) ?w)))
       (save-excursion (insert closer))))))
 
-(defun electric-pair-delete-selection-self-insert-function ()
-  (let ((syntax (electric-pair-syntax last-command-event)))
-    (if (and (memq syntax '(?\( ?\" ?\$)) (use-region-p))
-       'keep
-      t)))
+(defun electric-pair-will-use-region ()
+  (and (use-region-p)
+       (memq (electric-pair-syntax last-command-event) '(?\( ?\" ?\$))))
 
 ;;;###autoload
 (define-minor-mode electric-pair-mode
@@ -380,15 +378,14 @@
   :group 'electricity
   (if electric-pair-mode
       (progn
-       (require 'delsel)
        (add-hook 'post-self-insert-hook
                  #'electric-pair-post-self-insert-function)
-       (add-hook 'delete-selection-self-insert-hooks
-                 #'electric-pair-delete-selection-self-insert-function))
+       (add-hook 'self-insert-uses-region-functions
+                 #'electric-pair-will-use-region))
     (remove-hook 'post-self-insert-hook
                  #'electric-pair-post-self-insert-function)
-    (remove-hook 'delete-selection-self-insert-hooks
-                 #'electric-pair-delete-selection-self-insert-function)))
+    (remove-hook 'self-insert-uses-region-functions
+                 #'electric-pair-will-use-region)))
 
 ;; Automatically add newlines after/before/around some chars.
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]