Now on revision 110625. ------------------------------------------------------------ revno: 110625 committer: Chong Yidong branch nick: trunk timestamp: Tue 2012-10-23 10:39:13 +0800 message: Make unused variable font-list-limit obsolete, and move it out of C. * display.texi (Font Lookup): Remove font-list-limit. * lisp/startup.el (command-line): * lisp/cus-start.el: Don't refer to font-list-limit. * lisp/faces.el (font-list-limit): Define as an obsolete variable. * xfaces.c (Vfont_list_limit): Move unused variable to faces.el. diff: === modified file 'doc/lispref/ChangeLog' --- doc/lispref/ChangeLog 2012-10-23 02:23:39 +0000 +++ doc/lispref/ChangeLog 2012-10-23 02:39:13 +0000 @@ -1,5 +1,7 @@ 2012-10-23 Chong Yidong + * display.texi (Font Lookup): Remove font-list-limit. + * keymaps.texi (Key Sequences): Avoid referring to Edit Macro mode (Bug#12529). === modified file 'doc/lispref/display.texi' --- doc/lispref/display.texi 2012-10-13 01:18:52 +0000 +++ doc/lispref/display.texi 2012-10-23 02:39:13 +0000 @@ -2944,14 +2944,6 @@ encoding of the font. @end defun -@defopt font-list-limit -This variable specifies maximum number of fonts to consider in font -matching. The function @code{x-family-fonts} will not return more -than that many fonts, and font selection will consider only that many -fonts when searching a matching font for face attributes. The default -is 100. -@end defopt - @node Fontsets @subsection Fontsets === modified file 'etc/NEWS' --- etc/NEWS 2012-10-15 21:00:19 +0000 +++ etc/NEWS 2012-10-23 02:39:13 +0000 @@ -890,6 +890,7 @@ *** `window-system-version' *** `dired-pop-to-buffer' (use `dired-mark-pop-up') *** `query-replace-interactive' +*** `font-list-limit' (has had no effect since Emacs < 23) * Changes in Emacs 24.3 on non-free operating systems === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-23 02:17:36 +0000 +++ lisp/ChangeLog 2012-10-23 02:39:13 +0000 @@ -1,5 +1,10 @@ 2012-10-23 Chong Yidong + * faces.el (font-list-limit): Define as an obsolete variable. + + * startup.el (command-line): + * cus-start.el: Don't refer to font-list-limit. + * newcomment.el (comment-normalize-vars): Doc fix (Bug#12583). 2012-10-23 Stefan Monnier === modified file 'lisp/cus-start.el' --- lisp/cus-start.el 2012-10-08 07:18:02 +0000 +++ lisp/cus-start.el 2012-10-23 02:39:13 +0000 @@ -487,7 +487,6 @@ (hourglass-delay cursor number) ;; xfaces.c - (font-list-limit display integer) (scalable-fonts-allowed display boolean "22.1") ;; xfns.c (x-bitmap-file-path installation === modified file 'lisp/faces.el' --- lisp/faces.el 2012-10-07 22:31:58 +0000 +++ lisp/faces.el 2012-10-23 02:39:13 +0000 @@ -2572,6 +2572,12 @@ (car fonts)) (cdr (assq 'font (frame-parameters (selected-frame)))))) +(defcustom font-list-limit 100 + "This variable is obsolete and has no effect." + :type 'integer + :group 'display) +(make-obsolete-variable 'font-list-limit nil "24.3") + (provide 'faces) ;;; faces.el ends here === modified file 'lisp/startup.el' --- lisp/startup.el 2012-10-07 22:31:58 +0000 +++ lisp/startup.el 2012-10-23 02:39:13 +0000 @@ -971,7 +971,6 @@ (not (eq 0 (cdr tool-bar-lines))))))) (let ((old-scalable-fonts-allowed scalable-fonts-allowed) - (old-font-list-limit font-list-limit) (old-face-ignored-fonts face-ignored-fonts)) ;; Run the site-start library if it exists. The point of this file is @@ -1162,7 +1161,6 @@ ;; face realization, clear the face cache so that new faces will ;; be realized. (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed) - (eq font-list-limit old-font-list-limit) (eq face-ignored-fonts old-face-ignored-fonts)) (clear-face-cache))) === modified file 'src/ChangeLog' --- src/ChangeLog 2012-10-21 18:48:11 +0000 +++ src/ChangeLog 2012-10-23 02:39:13 +0000 @@ -1,3 +1,7 @@ +2012-10-23 Chong Yidong + + * xfaces.c (Vfont_list_limit): Move unused variable to faces.el. + 2012-10-21 Jan Djärv * nsfont.m (nsfont_open, ns_glyph_metrics): Force integer advancement === modified file 'src/xfaces.c' --- src/xfaces.c 2012-10-20 21:30:51 +0000 +++ src/xfaces.c 2012-10-23 02:39:13 +0000 @@ -371,8 +371,6 @@ static Lisp_Object Qscalable_fonts_allowed; -#define DEFAULT_FONT_LIST_LIMIT 100 - /* The symbols `foreground-color' and `background-color' which can be used as part of a `face' property. This is for compatibility with Emacs 20.2. */ @@ -6600,12 +6598,6 @@ defsubr (&Sdump_colors); #endif - DEFVAR_LISP ("font-list-limit", Vfont_list_limit, - doc: /* Limit for font matching. -If an integer > 0, font matching functions won't load more than -that number of fonts when searching for a matching font. */); - Vfont_list_limit = make_number (DEFAULT_FONT_LIST_LIMIT); - DEFVAR_LISP ("face-new-frame-defaults", Vface_new_frame_defaults, doc: /* List of global face definitions (for internal use only.) */); Vface_new_frame_defaults = Qnil; ------------------------------------------------------------ revno: 110624 fixes bug: http://debbugs.gnu.org/12529 committer: Chong Yidong branch nick: trunk timestamp: Tue 2012-10-23 10:23:39 +0800 message: * doc/lispref/keymaps.texi (Key Sequences): Avoid referring to Edit Macro mode. * doc/emacs/kmacro.texi (Edit Keyboard Macro): Fix typo. diff: === modified file 'doc/emacs/ChangeLog' --- doc/emacs/ChangeLog 2012-10-18 03:27:17 +0000 +++ doc/emacs/ChangeLog 2012-10-23 02:23:39 +0000 @@ -1,3 +1,7 @@ +2012-10-23 Chong Yidong + + * kmacro.texi (Edit Keyboard Macro): Fix typo. + 2012-10-18 Dani Moncayo * mini.texi (Completion Options): Fix off-by-one error. (Bug#12644) === modified file 'doc/emacs/kmacro.texi' --- doc/emacs/kmacro.texi 2012-05-27 01:25:06 +0000 +++ doc/emacs/kmacro.texi 2012-10-23 02:23:39 +0000 @@ -482,10 +482,11 @@ @kindex C-x C-k C-e @kindex C-x C-k RET You can edit the last keyboard macro by typing @kbd{C-x C-k C-e} or -@kbd{C-x C-k RET} (@code{kmacro-edit-macro}). This formats the macro -definition in a buffer and enters a specialized major mode for editing -it. Type @kbd{C-h m} once in that buffer to display details of how to -edit the macro. When you are finished editing, type @kbd{C-c C-c}. +@kbd{C-x C-k @key{RET}} (@code{kmacro-edit-macro}). This formats the +macro definition in a buffer and enters a specialized major mode for +editing it. Type @kbd{C-h m} once in that buffer to display details +of how to edit the macro. When you are finished editing, type +@kbd{C-c C-c}. @findex edit-kbd-macro @kindex C-x C-k e === modified file 'doc/lispref/ChangeLog' --- doc/lispref/ChangeLog 2012-10-22 21:57:14 +0000 +++ doc/lispref/ChangeLog 2012-10-23 02:23:39 +0000 @@ -1,3 +1,8 @@ +2012-10-23 Chong Yidong + + * keymaps.texi (Key Sequences): Avoid referring to Edit Macro mode + (Bug#12529). + 2012-10-22 Glenn Morris * os.texi (Recording Input): Tiny fix. === modified file 'doc/lispref/keymaps.texi' --- doc/lispref/keymaps.texi 2012-09-23 10:46:50 +0000 +++ doc/lispref/keymaps.texi 2012-10-23 02:23:39 +0000 @@ -78,11 +78,11 @@ @defmac kbd keyseq-text This macro converts the text @var{keyseq-text} (a string constant) into a key sequence (a string or vector constant). The contents of -@var{keyseq-text} should describe the key sequence using almost the same -syntax used in this manual. More precisely, it uses the same syntax -that Edit Macro mode uses for editing keyboard macros (@pxref{Edit -Keyboard Macro,,, emacs, The GNU Emacs Manual}); you must surround -function key names with @samp{<@dots{}>}. +@var{keyseq-text} should use the same syntax as in the buffer invoked +by the @kbd{C-x C-k @key{RET}} (@code{kmacro-edit-macro}) command; in +particular, you must surround function key names with +@samp{<@dots{}>}. @xref{Edit Keyboard Macro,,, emacs, The GNU Emacs +Manual}. @example (kbd "C-x") @result{} "\C-x" ------------------------------------------------------------ revno: 110623 fixes bug: http://debbugs.gnu.org/12583 committer: Chong Yidong branch nick: trunk timestamp: Tue 2012-10-23 10:17:36 +0800 message: * lisp/newcomment.el (comment-normalize-vars): Doc fix. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-23 01:18:47 +0000 +++ lisp/ChangeLog 2012-10-23 02:17:36 +0000 @@ -1,3 +1,7 @@ +2012-10-23 Chong Yidong + + * newcomment.el (comment-normalize-vars): Doc fix (Bug#12583). + 2012-10-23 Stefan Monnier * subr.el (internal-temp-output-buffer-show): Rename from === modified file 'lisp/newcomment.el' --- lisp/newcomment.el 2012-10-09 16:37:51 +0000 +++ lisp/newcomment.el 2012-10-23 02:17:36 +0000 @@ -24,7 +24,13 @@ ;;; Commentary: -;; A replacement for simple.el's comment-related functions. +;; This library contains functions and variables for commenting and +;; uncommenting source code. + +;; Prior to calling any `comment-*' function, you should ensure that +;; `comment-normalize-vars' is first called to set up the appropriate +;; variables; except for the `comment-*' commands, which call +;; `comment-normalize-vars' automatically as a subroutine. ;;; Bugs: @@ -326,10 +332,11 @@ ;;;###autoload (defun comment-normalize-vars (&optional noerror) - "Check and setup the variables needed by other commenting functions. -Any command calling functions from newcomment.el should call this function -before any other, so the rest of the code can assume that the variables are -properly set." + "Check and set up variables needed by other commenting functions. +All the `comment-*' commands call this function to set up various +variables, like `comment-start', to ensure that the commenting +functions work correctly. Lisp callers of any other `comment-*' +function should first call this function explicitly." (unless (and (not comment-start) noerror) (unless comment-start (let ((cs (read-string "No comment syntax is defined. Use: "))) ------------------------------------------------------------ revno: 110622 committer: Stefan Monnier branch nick: trunk timestamp: Mon 2012-10-22 21:18:47 -0400 message: * lisp/subr.el (internal-temp-output-buffer-show): Rename from temp-output-buffer-show, since previously compiled files expect this name. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-23 00:46:11 +0000 +++ lisp/ChangeLog 2012-10-23 01:18:47 +0000 @@ -1,3 +1,8 @@ +2012-10-23 Stefan Monnier + + * subr.el (internal-temp-output-buffer-show): Rename from + temp-output-buffer-show, since previously compiled files expect this name. + 2012-10-23 Glenn Morris * image.el (image-type-from-file-name): If multiple types match, === modified file 'lisp/subr.el' --- lisp/subr.el 2012-10-07 19:48:02 +0000 +++ lisp/subr.el 2012-10-23 01:18:47 +0000 @@ -3151,7 +3151,7 @@ (unwind-protect (progn ,@body) (set-window-configuration ,c))))) -(defun temp-output-buffer-show (buffer) +(defun internal-temp-output-buffer-show (buffer) "Internal function for `with-output-to-temp-buffer'." (with-current-buffer buffer (set-buffer-modified-p nil) @@ -3235,7 +3235,7 @@ (run-hooks 'temp-buffer-setup-hook))))) (standard-output ,buf)) (prog1 (progn ,@body) - (temp-output-buffer-show ,buf))))) + (internal-temp-output-buffer-show ,buf))))) (defmacro with-temp-file (file &rest body) "Create a new buffer, evaluate BODY there, and write the buffer to FILE. ------------------------------------------------------------ revno: 110621 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-10-22 20:46:11 -0400 message: image-type-from-file-name fix for bug#9045 * lisp/image.el (image-type-from-file-name): If multiple types match, return the first one that is supported. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-22 21:53:03 +0000 +++ lisp/ChangeLog 2012-10-23 00:46:11 +0000 @@ -1,3 +1,8 @@ +2012-10-23 Glenn Morris + + * image.el (image-type-from-file-name): If multiple types match, + return the first one that is supported. (Bug#9045) + 2012-10-22 Glenn Morris * image.el (imagemagick-enabled-types): Doc fix. === modified file 'lisp/image.el' --- lisp/image.el 2012-10-22 21:53:03 +0000 +++ lisp/image.el 2012-10-23 00:46:11 +0000 @@ -308,8 +308,17 @@ "Determine the type of image file FILE from its name. Value is a symbol specifying the image type, or nil if type cannot be determined." - (assoc-default file image-type-file-name-regexps 'string-match-p)) - + (let (type first) + (or + (catch 'found + (dolist (elem image-type-file-name-regexps) + (when (string-match-p (car elem) file) + (setq type (cdr elem)) + (or first (setq first type)) + (if (image-type-available-p type) + (throw 'found type))))) + ;; If nothing seems to be supported, return the first type that matched. + first))) ;;;###autoload (defun image-type (source &optional type data-p) ------------------------------------------------------------ revno: 110620 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-10-22 17:57:14 -0400 message: * doc/lispref/os.texi (Recording Input): Tiny fix. diff: === modified file 'doc/lispref/ChangeLog' --- doc/lispref/ChangeLog 2012-10-22 02:22:27 +0000 +++ doc/lispref/ChangeLog 2012-10-22 21:57:14 +0000 @@ -1,5 +1,7 @@ 2012-10-22 Glenn Morris + * os.texi (Recording Input): Tiny fix. + * intro.texi (Lisp History): * lists.texi (Sets And Lists): Refer to cl-lib rather than cl. * tips.texi (Coding Conventions): Recommend cl-lib over cl. === modified file 'doc/lispref/os.texi' --- doc/lispref/os.texi 2012-09-30 09:18:38 +0000 +++ doc/lispref/os.texi 2012-10-22 21:57:14 +0000 @@ -1963,7 +1963,7 @@ This function returns a vector containing the last 300 input events from the keyboard or mouse. All input events are included, whether or not they were used as parts of key sequences. Thus, you always get the last -100 input events, not counting events generated by keyboard macros. +300 input events, not counting events generated by keyboard macros. (These are excluded because they are less interesting for debugging; it should be enough to see the events that invoked the macros.) ------------------------------------------------------------ revno: 110619 committer: Glenn Morris branch nick: trunk timestamp: Mon 2012-10-22 17:53:03 -0400 message: * lisp/image.el (imagemagick-enabled-types): Doc fix. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-22 13:29:28 +0000 +++ lisp/ChangeLog 2012-10-22 21:53:03 +0000 @@ -1,3 +1,7 @@ +2012-10-22 Glenn Morris + + * image.el (imagemagick-enabled-types): Doc fix. + 2012-10-22 Takafumi Arakaki (tiny change) * progmodes/which-func.el (which-func-current): The hash-table may have === modified file 'lisp/image.el' --- lisp/image.el 2012-09-23 09:16:57 +0000 +++ lisp/image.el 2012-10-22 21:53:03 +0000 @@ -798,7 +798,7 @@ The variable `imagemagick-types-inhibit' overrides this variable. -If you change this without outside of Customize, you must call +If you change this without using customize, you must call `imagemagick-register-types' afterwards. If Emacs is compiled without ImageMagick support, this variable ------------------------------------------------------------ revno: 110618 fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12338 author: Takafumi Arakaki committer: Stefan Monnier branch nick: trunk timestamp: Mon 2012-10-22 09:29:28 -0400 message: * lisp/progmodes/which-func.el (which-func-current): The hash-table may have an explicit nil. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-22 12:43:54 +0000 +++ lisp/ChangeLog 2012-10-22 13:29:28 +0000 @@ -1,3 +1,8 @@ +2012-10-22 Takafumi Arakaki (tiny change) + + * progmodes/which-func.el (which-func-current): The hash-table may have + an explicit nil (bug#12338). + 2012-10-22 Stefan Monnier * electric.el (electric-pair-delete-selection-self-insert-function): === modified file 'lisp/progmodes/which-func.el' --- lisp/progmodes/which-func.el 2012-09-25 04:13:02 +0000 +++ lisp/progmodes/which-func.el 2012-10-22 13:29:28 +0000 @@ -182,7 +182,8 @@ (defconst which-func-current '(:eval (replace-regexp-in-string "%" "%%" - (gethash (selected-window) which-func-table which-func-unknown)))) + (or (gethash (selected-window) which-func-table) + which-func-unknown)))) ;;;###autoload (put 'which-func-current 'risky-local-variable t) (defvar which-func-mode nil ------------------------------------------------------------ revno: 110617 committer: Stefan Monnier 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. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-22 03:15:44 +0000 +++ lisp/ChangeLog 2012-10-22 12:43:54 +0000 @@ -1,3 +1,17 @@ +2012-10-22 Stefan Monnier + + * 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 (tiny change) * delsel.el (delete-selection-helper): New function, extracted from === modified file 'lisp/delsel.el' --- lisp/delsel.el 2012-10-22 03:15:44 +0000 +++ 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 +;; ;; 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' --- lisp/electric.el 2012-10-22 03:15:44 +0000 +++ 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. ------------------------------------------------------------ revno: 110616 fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11520 author: Simon Law committer: Stefan Monnier branch nick: trunk timestamp: Sun 2012-10-21 23:15:44 -0400 message: * lisp/delsel.el (delete-selection-helper): New function, extracted from delete-selection-pre-hook. (delete-selection-pre-hook): Use it. (delete-selection-self-insert-function): New function. (delete-selection-self-insert-hooks): New hook. (self-insert-command, self-insert-iso): Use it. * lisp/electric.el (electric-pair-syntax): New function, extracted from electric-pair-post-self-insert-function. (electric-pair-post-self-insert-function): Use it. (electric-pair-delete-selection-self-insert-function): New function. (electric-pair-mode): Require delsel and setup delete-selection-self-insert-hooks. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-10-20 12:04:45 +0000 +++ lisp/ChangeLog 2012-10-22 03:15:44 +0000 @@ -1,3 +1,18 @@ +2012-10-22 Simon Law (tiny change) + + * delsel.el (delete-selection-helper): New function, extracted from + delete-selection-pre-hook. + (delete-selection-pre-hook): Use it. + (delete-selection-self-insert-function): New function. + (delete-selection-self-insert-hooks): New hook. + (self-insert-command, self-insert-iso): Use it. + * electric.el (electric-pair-syntax): New function, extracted from + electric-pair-post-self-insert-function. + (electric-pair-post-self-insert-function): Use it. + (electric-pair-delete-selection-self-insert-function): New function. + (electric-pair-mode): Require delsel and setup + delete-selection-self-insert-hooks (bug#11520). + 2012-10-20 Chong Yidong * vc/vc.el (vc-diff-internal): Set up Diff mode even if there are @@ -8,8 +23,8 @@ 2012-10-20 Arne Jørgensen - * progmodes/flymake.el (flymake-create-temp-inplace): Use - file-truename. + * progmodes/flymake.el (flymake-create-temp-inplace): + Use file-truename. 2012-10-20 Eli Zaretskii === modified file 'lisp/delsel.el' --- lisp/delsel.el 2012-08-09 02:18:50 +0000 +++ lisp/delsel.el 2012-10-22 03:15:44 +0000 @@ -47,6 +47,9 @@ ;; non-nil ;; The normal case: delete the active region prior to executing ;; the command which will insert replacement text. +;; hooks +;; For commands which need to dynamically determine this behaviour. +;; Each hook should return one of the above values or nil. ;;; Code: @@ -71,66 +74,106 @@ (transient-mark-mode t))) (defun delete-active-region (&optional killp) + "Delete the active region. +If KILLP in not-nil, the active region is killed instead of deleted." (if killp (kill-region (point) (mark)) (delete-region (point) (mark))) t) +(defun delete-selection-helper (type) + "Deletes selection according to TYPE: + 'yank + For commands which do a yank; ensures the region about to be + deleted isn't yanked. + 'supersede + Delete the active region and ignore the current command, + i.e. the command will just delete the region. + 'kill + `kill-region' is used on the selection, rather than + `delete-region'. (Text selected with the mouse will typically + be yankable anyhow.) + non-nil + The normal case: delete the active region prior to executing + the command which will insert replacement text. + hooks + For commands which need to dynamically determine this behaviour. + Each hook should return one of the above values or nil." + (condition-case data + (cond ((eq type 'kill) + (delete-active-region t)) + ((eq type 'yank) + ;; Before a yank command, make sure we don't yank the + ;; head of the kill-ring that really comes from the + ;; currently active region we are going to delete. + ;; That would make yank a no-op. + (when (and (string= (buffer-substring-no-properties + (point) (mark)) + (car kill-ring)) + (fboundp 'mouse-region-match) + (mouse-region-match)) + (current-kill 1)) + (delete-active-region)) + ((eq type 'supersede) + (let ((empty-region (= (point) (mark)))) + (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))) + (type + (delete-active-region) + (if (and overwrite-mode + (eq this-command 'self-insert-command)) + (let ((overwrite-mode nil)) + (self-insert-command + (prefix-numeric-value current-prefix-arg)) + (setq this-command 'ignore))))) + ;; If ask-user-about-supersession-threat signals an error, + ;; stop safe_run_hooks from clearing out pre-command-hook. + (file-supersession (message "%s" (cadr data)) (ding)) + (text-read-only + ;; This signal may come either from `delete-active-region' or + ;; `self-insert-command' (when `overwrite-mode' is non-nil). + ;; To avoid clearing out `pre-command-hook' we handle this case + ;; by issuing a simple message. Note, however, that we do not + ;; handle all related problems: When read-only text ends before + ;; the end of the region, the latter is not deleted but any + ;; subsequent insertion will succeed. We could avoid this case + ;; by doing a (setq this-command 'ignore) here. This would, + ;; however, still not handle the case where read-only text ends + ;; precisely where the region starts: In that case the deletion + ;; would succeed but the subsequent insertion would fail with a + ;; text-read-only error. To handle that case we would have to + ;; investigate text properties at both ends of the region and + ;; skip the deletion when inserting text is forbidden there. + (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 +have this property won't delete the selection. + +See `delete-selection-helper'. +" (when (and delete-selection-mode transient-mark-mode mark-active (not buffer-read-only)) (let ((type (and (symbolp this-command) (get this-command 'delete-selection)))) - (condition-case data - (cond ((eq type 'kill) - (delete-active-region t)) - ((eq type 'yank) - ;; Before a yank command, make sure we don't yank the - ;; head of the kill-ring that really comes from the - ;; currently active region we are going to delete. - ;; That would make yank a no-op. - (when (and (string= (buffer-substring-no-properties - (point) (mark)) - (car kill-ring)) - (fboundp 'mouse-region-match) - (mouse-region-match)) - (current-kill 1)) - (delete-active-region)) - ((eq type 'supersede) - (let ((empty-region (= (point) (mark)))) - (delete-active-region) - (unless empty-region - (setq this-command 'ignore)))) - (type - (delete-active-region) - (if (and overwrite-mode - (eq this-command 'self-insert-command)) - (let ((overwrite-mode nil)) - (self-insert-command - (prefix-numeric-value current-prefix-arg)) - (setq this-command 'ignore))))) - ;; If ask-user-about-supersession-threat signals an error, - ;; stop safe_run_hooks from clearing out pre-command-hook. - (file-supersession (message "%s" (cadr data)) (ding)) - (text-read-only - ;; This signal may come either from `delete-active-region' or - ;; `self-insert-command' (when `overwrite-mode' is non-nil). - ;; To avoid clearing out `pre-command-hook' we handle this case - ;; by issuing a simple message. Note, however, that we do not - ;; handle all related problems: When read-only text ends before - ;; the end of the region, the latter is not deleted but any - ;; subsequent insertion will succeed. We could avoid this case - ;; by doing a (setq this-command 'ignore) here. This would, - ;; however, still not handle the case where read-only text ends - ;; precisely where the region starts: In that case the deletion - ;; would succeed but the subsequent insertion would fail with a - ;; text-read-only error. To handle that case we would have to - ;; investigate text properties at both ends of the region and - ;; skip the deletion when inserting text is forbidden there. - (message "Text is read-only") (ding)))))) - -(put 'self-insert-command 'delete-selection t) -(put 'self-insert-iso 'delete-selection t) + (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) (put 'yank 'delete-selection 'yank) (put 'clipboard-yank 'delete-selection 'yank) === modified file 'lisp/electric.el' --- lisp/electric.el 2012-07-14 05:32:23 +0000 +++ lisp/electric.el 2012-10-22 03:15:44 +0000 @@ -301,14 +301,17 @@ :version "24.1" :type 'boolean) +(defun electric-pair-syntax (command-event) + (and electric-pair-mode + (let ((x (assq command-event electric-pair-pairs))) + (cond + (x (if (eq (car x) (cdr x)) ?\" ?\()) + ((rassq command-event electric-pair-pairs) ?\)) + (t (char-syntax command-event)))))) + (defun electric-pair-post-self-insert-function () (let* ((syntax (and (eq (char-before) last-command-event) ; Sanity check. - electric-pair-mode - (let ((x (assq last-command-event electric-pair-pairs))) - (cond - (x (if (eq (car x) (cdr x)) ?\" ?\()) - ((rassq last-command-event electric-pair-pairs) ?\)) - (t (char-syntax last-command-event)))))) + (electric-pair-syntax last-command-event))) ;; FIXME: when inserting the closer, we should maybe use ;; self-insert-command, although it may prove tricky running ;; post-self-insert-hook recursively, and we wouldn't want to trigger @@ -355,6 +358,12 @@ (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))) + ;;;###autoload (define-minor-mode electric-pair-mode "Toggle automatic parens pairing (Electric Pair mode). @@ -370,10 +379,16 @@ :global t :group 'electricity (if electric-pair-mode - (add-hook 'post-self-insert-hook - #'electric-pair-post-self-insert-function) + (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)) (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 + #'electric-pair-delete-selection-self-insert-function))) ;; Automatically add newlines after/before/around some chars.