emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 82a3da2: Make electric-pair-mode, delete-selection-


From: Alan Mackenzie
Subject: [Emacs-diffs] master 82a3da2: Make electric-pair-mode, delete-selection-mode and CC Mode cooperate.
Date: Wed, 19 Aug 2015 16:48:21 +0000

branch: master
commit 82a3da21ffece64ce9f4f99f35cbc0afe851e6ee
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    Make electric-pair-mode, delete-selection-mode and CC Mode cooperate.
    
    Fixes debbugs#21275.
    
    In Emacs >= 25, let electric-pair-mode take precedence over
    delete-selection-mode.
    delsel.el (delete-selection-uses-region-p): New function, previously a
    lambda expression in a property value for `self-insert-command'.
    (top-level) Set the `delete-selection' property of `self-insert-command'
    to `delete-selection-uses-region-p'.
    
    progmodes/cc-cmds.el (top-level): Give the `delete-selection' property
    for c-electric-\(brace\|paren\) the value `delete-selection-uses-region-p'
    when the latter function exists.
---
 lisp/delsel.el            |   15 +++++++++++----
 lisp/progmodes/cc-cmds.el |   15 ++++++++++++---
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/lisp/delsel.el b/lisp/delsel.el
index 740b603..586c130 100644
--- a/lisp/delsel.el
+++ b/lisp/delsel.el
@@ -231,10 +231,17 @@ See `delete-selection-helper'."
     (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))))
+(defun delete-selection-uses-region-p ()
+  "Return t when the current command will be using the region
+rather than having `delete-selection' delete it, nil otherwise.
+
+This function is intended for use as the value of the
+`delete-selection' property of a command, and shouldn't be used
+for anything else."
+  (not (run-hook-with-args-until-success
+        'self-insert-uses-region-functions)))
+
+(put 'self-insert-command 'delete-selection 'delete-selection-uses-region-p)
 
 (put 'insert-char 'delete-selection t)
 (put 'quoted-insert 'delete-selection t)
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index c9f5945..0beaf26 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -2853,19 +2853,28 @@ sentence motion in or near comments and multiline 
strings."
 
 ;; set up electric character functions to work with pending-del,
 ;; (a.k.a. delsel) mode.  All symbols get the t value except
-;; the functions which delete, which gets 'supersede.
+;; the functions which delete, which gets 'supersede, and (from Emacs
+;; 25) `c-electric-brace' and `c-electric-paren' get special handling
+;; so as to work gracefully with `electric-pair-mode'.
 (mapc
  (function
   (lambda (sym)
     (put sym 'delete-selection t)      ; for delsel (Emacs)
     (put sym 'pending-delete t)))      ; for pending-del (XEmacs)
  '(c-electric-pound
-   c-electric-brace
    c-electric-slash
    c-electric-star
    c-electric-semi&comma
    c-electric-lt-gt
-   c-electric-colon
+   c-electric-colon))
+(mapc
+ (function
+  (lambda (sym)
+    (put sym 'delete-selection (if (fboundp 'delete-selection-uses-region-p)
+                                  'delete-selection-uses-region-p
+                                t))
+    (put sym 'pending-delete t)))
+ '(c-electric-brace
    c-electric-paren))
 (put 'c-electric-delete    'delete-selection 'supersede) ; delsel
 (put 'c-electric-delete    'pending-delete   'supersede) ; pending-del



reply via email to

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