mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-22 07:09:54 +00:00
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.
This commit is contained in:
parent
b1d39ccce4
commit
c77d37e227
@ -1,3 +1,17 @@
|
|||||||
|
2012-10-22 Stefan Monnier <monnier@iro.umontreal.ca>
|
||||||
|
|
||||||
|
* 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 <sfllaw@sfllaw.ca> (tiny change)
|
2012-10-22 Simon Law <sfllaw@sfllaw.ca> (tiny change)
|
||||||
|
|
||||||
* delsel.el (delete-selection-helper): New function, extracted from
|
* delsel.el (delete-selection-helper): New function, extracted from
|
||||||
|
@ -44,12 +44,12 @@
|
|||||||
;; `kill-region' is used on the selection, rather than
|
;; `kill-region' is used on the selection, rather than
|
||||||
;; `delete-region'. (Text selected with the mouse will typically
|
;; `delete-region'. (Text selected with the mouse will typically
|
||||||
;; be yankable anyhow.)
|
;; be yankable anyhow.)
|
||||||
;; non-nil
|
;; t
|
||||||
;; The normal case: delete the active region prior to executing
|
;; The normal case: delete the active region prior to executing
|
||||||
;; the command which will insert replacement text.
|
;; the command which will insert replacement text.
|
||||||
;; hooks
|
;; <function>
|
||||||
;; For commands which need to dynamically determine this behaviour.
|
;; 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:
|
;;; Code:
|
||||||
|
|
||||||
@ -82,23 +82,23 @@ If KILLP in not-nil, the active region is killed instead of deleted."
|
|||||||
t)
|
t)
|
||||||
|
|
||||||
(defun delete-selection-helper (type)
|
(defun delete-selection-helper (type)
|
||||||
"Deletes selection according to TYPE:
|
"Delete selection according to TYPE:
|
||||||
'yank
|
`yank'
|
||||||
For commands which do a yank; ensures the region about to be
|
For commands which do a yank; ensures the region about to be
|
||||||
deleted isn't yanked.
|
deleted isn't yanked.
|
||||||
'supersede
|
`supersede'
|
||||||
Delete the active region and ignore the current command,
|
Delete the active region and ignore the current command,
|
||||||
i.e. the command will just delete the region.
|
i.e. the command will just delete the region.
|
||||||
'kill
|
`kill'
|
||||||
`kill-region' is used on the selection, rather than
|
`kill-region' is used on the selection, rather than
|
||||||
`delete-region'. (Text selected with the mouse will typically
|
`delete-region'. (Text selected with the mouse will typically
|
||||||
be yankable anyhow.)
|
be yankable anyhow.)
|
||||||
non-nil
|
t
|
||||||
The normal case: delete the active region prior to executing
|
The normal case: delete the active region prior to executing
|
||||||
the command which will insert replacement text.
|
the command which will insert replacement text.
|
||||||
hooks
|
FUNCTION
|
||||||
For commands which need to dynamically determine this behaviour.
|
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
|
(condition-case data
|
||||||
(cond ((eq type 'kill)
|
(cond ((eq type 'kill)
|
||||||
(delete-active-region t))
|
(delete-active-region t))
|
||||||
@ -119,9 +119,7 @@ If KILLP in not-nil, the active region is killed instead of deleted."
|
|||||||
(delete-active-region)
|
(delete-active-region)
|
||||||
(unless empty-region
|
(unless empty-region
|
||||||
(setq this-command 'ignore))))
|
(setq this-command 'ignore))))
|
||||||
((and (symbolp type) (not (booleanp type)))
|
((functionp type) (delete-selection-helper (funcall type)))
|
||||||
(delete-selection-helper
|
|
||||||
(run-hook-with-args-until-success type)))
|
|
||||||
(type
|
(type
|
||||||
(delete-active-region)
|
(delete-active-region)
|
||||||
(if (and overwrite-mode
|
(if (and overwrite-mode
|
||||||
@ -151,29 +149,22 @@ If KILLP in not-nil, the active region is killed instead of deleted."
|
|||||||
(message "Text is read-only") (ding))))
|
(message "Text is read-only") (ding))))
|
||||||
|
|
||||||
(defun delete-selection-pre-hook ()
|
(defun delete-selection-pre-hook ()
|
||||||
"Normal hook run before commands that delete selections are executed.
|
"Function run before commands that delete selections are executed.
|
||||||
Commands which will delete the selection need a 'delete-selection
|
Commands which will delete the selection need a `delete-selection'
|
||||||
property on their symbols; commands which insert text but don't
|
property on their symbol; commands which insert text but don't
|
||||||
have this property won't delete the selection.
|
have this property won't delete the selection.
|
||||||
|
See `delete-selection-helper'."
|
||||||
See `delete-selection-helper'.
|
(when (and delete-selection-mode (use-region-p)
|
||||||
"
|
|
||||||
(when (and delete-selection-mode transient-mark-mode mark-active
|
|
||||||
(not buffer-read-only))
|
(not buffer-read-only))
|
||||||
(let ((type (and (symbolp this-command)
|
(delete-selection-helper (and (symbolp this-command)
|
||||||
(get this-command 'delete-selection))))
|
(get this-command 'delete-selection)))))
|
||||||
(delete-selection-helper type))))
|
|
||||||
|
|
||||||
(defun delete-selection-self-insert-function ()
|
(put 'self-insert-command 'delete-selection
|
||||||
t)
|
(lambda ()
|
||||||
|
(not (run-hook-with-args-until-success
|
||||||
|
'self-insert-uses-region-functions))))
|
||||||
|
|
||||||
(defvar delete-selection-self-insert-hooks
|
(put 'self-insert-iso 'delete-selection t)
|
||||||
'(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)
|
|
||||||
|
|
||||||
(put 'yank 'delete-selection 'yank)
|
(put 'yank 'delete-selection 'yank)
|
||||||
(put 'clipboard-yank 'delete-selection 'yank)
|
(put 'clipboard-yank 'delete-selection 'yank)
|
||||||
|
@ -358,11 +358,9 @@ This can be convenient for people who find it easier to hit ) than C-f."
|
|||||||
(eq (char-syntax (following-char)) ?w)))
|
(eq (char-syntax (following-char)) ?w)))
|
||||||
(save-excursion (insert closer))))))
|
(save-excursion (insert closer))))))
|
||||||
|
|
||||||
(defun electric-pair-delete-selection-self-insert-function ()
|
(defun electric-pair-will-use-region ()
|
||||||
(let ((syntax (electric-pair-syntax last-command-event)))
|
(and (use-region-p)
|
||||||
(if (and (memq syntax '(?\( ?\" ?\$)) (use-region-p))
|
(memq (electric-pair-syntax last-command-event) '(?\( ?\" ?\$))))
|
||||||
'keep
|
|
||||||
t)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode electric-pair-mode
|
(define-minor-mode electric-pair-mode
|
||||||
@ -380,15 +378,14 @@ See options `electric-pair-pairs' and `electric-pair-skip-self'."
|
|||||||
:group 'electricity
|
:group 'electricity
|
||||||
(if electric-pair-mode
|
(if electric-pair-mode
|
||||||
(progn
|
(progn
|
||||||
(require 'delsel)
|
|
||||||
(add-hook 'post-self-insert-hook
|
(add-hook 'post-self-insert-hook
|
||||||
#'electric-pair-post-self-insert-function)
|
#'electric-pair-post-self-insert-function)
|
||||||
(add-hook 'delete-selection-self-insert-hooks
|
(add-hook 'self-insert-uses-region-functions
|
||||||
#'electric-pair-delete-selection-self-insert-function))
|
#'electric-pair-will-use-region))
|
||||||
(remove-hook 'post-self-insert-hook
|
(remove-hook 'post-self-insert-hook
|
||||||
#'electric-pair-post-self-insert-function)
|
#'electric-pair-post-self-insert-function)
|
||||||
(remove-hook 'delete-selection-self-insert-hooks
|
(remove-hook 'self-insert-uses-region-functions
|
||||||
#'electric-pair-delete-selection-self-insert-function)))
|
#'electric-pair-will-use-region)))
|
||||||
|
|
||||||
;; Automatically add newlines after/before/around some chars.
|
;; Automatically add newlines after/before/around some chars.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user