Commit a2e5caf7 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

New post-self-insert-hook.

* src/cmds.c (Vself_insert_face, Vself_insert_face_command): Remove.
(Qpost_self_insert_hook, Vpost_self_insert_hook): New vars.
(internal_self_insert): Run post-self-insert-hook rather than handle
self-insert-face.
(syms_of_cmds): Initialize the new vars.
* lisp/facemenu.el (facemenu-self-insert-data): New var.
(facemenu-post-self-insert-function, facemenu-set-self-insert-face): New funs.
(facemenu-add-face): Use them.
parent 20d60baf
...@@ -453,6 +453,8 @@ has now been removed. ...@@ -453,6 +453,8 @@ has now been removed.
* Lisp changes in Emacs 24.1 * Lisp changes in Emacs 24.1
** New hook post-self-insert-hook run at the end of self-insert-command.
** Syntax tables support a new "comment style c" additionally to style b. ** Syntax tables support a new "comment style c" additionally to style b.
** frame-local variables cannot be let-bound any more. ** frame-local variables cannot be let-bound any more.
** prog-mode is a new major-mode meant to be the parent of programming mode. ** prog-mode is a new major-mode meant to be the parent of programming mode.
......
2010-08-19 Stefan Monnier <monnier@iro.umontreal.ca> 2010-08-19 Stefan Monnier <monnier@iro.umontreal.ca>
   
* facemenu.el (facemenu-self-insert-data): New var.
(facemenu-post-self-insert-function, facemenu-set-self-insert-face):
New functions.
(facemenu-add-face): Use them.
* simple.el (blink-matching-open): Obey forward-sexp-function. * simple.el (blink-matching-open): Obey forward-sexp-function.
   
2010-08-18 Stefan Monnier <monnier@iro.umontreal.ca> 2010-08-18 Stefan Monnier <monnier@iro.umontreal.ca>
......
...@@ -699,6 +699,22 @@ determine the correct answer." ...@@ -699,6 +699,22 @@ determine the correct answer."
(cond ((equal a b) t) (cond ((equal a b) t)
((equal (color-values a) (color-values b))))) ((equal (color-values a) (color-values b)))))
(defvar facemenu-self-insert-data nil)
(defun facemenu-post-self-insert-function ()
(when (and (car facemenu-self-insert-data)
(eq last-command (cdr facemenu-self-insert-data)))
(put-text-property (1- (point)) (point)
'face (car facemenu-self-insert-data))
(setq facemenu-self-insert-data nil))
(remove-hook 'post-self-insert-hook 'facemenu-post-self-insert-function))
(defun facemenu-set-self-insert-face (face)
"Arrange for the next self-inserted char to have face `face'."
(setq facemenu-self-insert-data (cons face this-command))
(add-hook 'post-self-insert-hook 'facemenu-post-self-insert-function))
(defun facemenu-add-face (face &optional start end) (defun facemenu-add-face (face &optional start end)
"Add FACE to text between START and END. "Add FACE to text between START and END.
If START is nil or START to END is empty, add FACE to next typed character If START is nil or START to END is empty, add FACE to next typed character
...@@ -712,51 +728,52 @@ As a special case, if FACE is `default', then the region is left with NO face ...@@ -712,51 +728,52 @@ As a special case, if FACE is `default', then the region is left with NO face
text property. Otherwise, selecting the default face would not have any text property. Otherwise, selecting the default face would not have any
effect. See `facemenu-remove-face-function'." effect. See `facemenu-remove-face-function'."
(interactive "*xFace: \nr") (interactive "*xFace: \nr")
(if (and (eq face 'default) (cond
(not (eq facemenu-remove-face-function t))) ((and (eq face 'default)
(if facemenu-remove-face-function (not (eq facemenu-remove-face-function t)))
(funcall facemenu-remove-face-function start end) (if facemenu-remove-face-function
(if (and start (< start end)) (funcall facemenu-remove-face-function start end)
(remove-text-properties start end '(face default))
(setq self-insert-face 'default
self-insert-face-command this-command)))
(if facemenu-add-face-function
(save-excursion
(if end (goto-char end))
(save-excursion
(if start (goto-char start))
(insert-before-markers
(funcall facemenu-add-face-function face end)))
(if facemenu-end-add-face
(insert (if (stringp facemenu-end-add-face)
facemenu-end-add-face
(funcall facemenu-end-add-face face)))))
(if (and start (< start end)) (if (and start (< start end))
(let ((part-start start) part-end) (remove-text-properties start end '(face default))
(while (not (= part-start end)) (facemenu-set-self-insert-face 'default))))
(setq part-end (next-single-property-change part-start 'face (facemenu-add-face-function
nil end)) (save-excursion
(let ((prev (get-text-property part-start 'face))) (if end (goto-char end))
(put-text-property part-start part-end 'face (save-excursion
(if (null prev) (if start (goto-char start))
face (insert-before-markers
(facemenu-active-faces (funcall facemenu-add-face-function face end)))
(cons face (if facemenu-end-add-face
(if (listp prev) (insert (if (stringp facemenu-end-add-face)
prev facemenu-end-add-face
(list prev))) (funcall facemenu-end-add-face face))))))
;; Specify the selected frame ((and start (< start end))
;; because nil would mean to use (let ((part-start start) part-end)
;; the new-frame default settings, (while (not (= part-start end))
;; and those are usually nil. (setq part-end (next-single-property-change part-start 'face
(selected-frame))))) nil end))
(setq part-start part-end))) (let ((prev (get-text-property part-start 'face)))
(setq self-insert-face (if (eq last-command self-insert-face-command) (put-text-property part-start part-end 'face
(cons face (if (listp self-insert-face) (if (null prev)
self-insert-face face
(list self-insert-face))) (facemenu-active-faces
face) (cons face
self-insert-face-command this-command)))) (if (listp prev)
prev
(list prev)))
;; Specify the selected frame
;; because nil would mean to use
;; the new-frame default settings,
;; and those are usually nil.
(selected-frame)))))
(setq part-start part-end))))
(t
(facemenu-set-self-insert-face
(if (eq last-command (cdr facemenu-self-insert-data))
(cons face (if (listp (car facemenu-self-insert-data))
(car facemenu-self-insert-data)
(list (car facemenu-self-insert-data))))
face))))
(unless (facemenu-enable-faces-p) (unless (facemenu-enable-faces-p)
(message "Font-lock mode will override any faces you set in this buffer"))) (message "Font-lock mode will override any faces you set in this buffer")))
......
2010-08-19 Stefan Monnier <monnier@iro.umontreal.ca>
* cmds.c (Vself_insert_face, Vself_insert_face_command): Remove.
(Qpost_self_insert_hook, Vpost_self_insert_hook): New vars.
(internal_self_insert): Run Qpost_self_insert_hook rather than handle
self-insert-face.
(syms_of_cmds): Initialize the new vars.
2010-08-19 Jason Rumney <jasonr@gnu.org> 2010-08-19 Jason Rumney <jasonr@gnu.org>
   
* w32fns.c (w32_wnd_proc): Don't check context before initializing. * w32fns.c (w32_wnd_proc): Don't check context before initializing.
......
...@@ -37,12 +37,6 @@ Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function; ...@@ -37,12 +37,6 @@ Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function;
/* A possible value for a buffer's overwrite-mode variable. */ /* A possible value for a buffer's overwrite-mode variable. */
Lisp_Object Qoverwrite_mode_binary; Lisp_Object Qoverwrite_mode_binary;
/* Non-nil means put this face on the next self-inserting character. */
Lisp_Object Vself_insert_face;
/* This is the command that set up Vself_insert_face. */
Lisp_Object Vself_insert_face_command;
static int internal_self_insert (int, int); static int internal_self_insert (int, int);
DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0, DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0,
...@@ -346,6 +340,7 @@ After insertion, the value of `auto-fill-function' is called if the ...@@ -346,6 +340,7 @@ After insertion, the value of `auto-fill-function' is called if the
A value of 2 means this did things that call for an undo boundary. */ A value of 2 means this did things that call for an undo boundary. */
static Lisp_Object Qexpand_abbrev; static Lisp_Object Qexpand_abbrev;
static Lisp_Object Qpost_self_insert_hook, Vpost_self_insert_hook;
static int static int
internal_self_insert (int c, int noautofill) internal_self_insert (int c, int noautofill)
...@@ -451,10 +446,10 @@ internal_self_insert (int c, int noautofill) ...@@ -451,10 +446,10 @@ internal_self_insert (int c, int noautofill)
&& synt != Sword && synt != Sword
&& NILP (current_buffer->read_only) && NILP (current_buffer->read_only)
&& PT > BEGV && PT > BEGV
&& (!NILP (current_buffer->enable_multibyte_characters) && (SYNTAX (!NILP (current_buffer->enable_multibyte_characters)
? SYNTAX (XFASTINT (Fprevious_char ())) == Sword ? XFASTINT (Fprevious_char ())
: (SYNTAX (UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ()))) : UNIBYTE_TO_CHAR (XFASTINT (Fprevious_char ())))
== Sword))) == Sword))
{ {
int modiff = MODIFF; int modiff = MODIFF;
Lisp_Object sym; Lisp_Object sym;
...@@ -514,15 +509,6 @@ internal_self_insert (int c, int noautofill) ...@@ -514,15 +509,6 @@ internal_self_insert (int c, int noautofill)
hairy = 2; hairy = 2;
} }
/* If previous command specified a face to use, use it. */
if (!NILP (Vself_insert_face)
&& EQ (current_kboard->Vlast_command, Vself_insert_face_command))
{
Fput_text_property (make_number (PT - 1), make_number (PT),
Qface, Vself_insert_face, Qnil);
Vself_insert_face = Qnil;
}
if ((synt == Sclose || synt == Smath) if ((synt == Sclose || synt == Smath)
&& !NILP (Vblink_paren_function) && INTERACTIVE && !NILP (Vblink_paren_function) && INTERACTIVE
&& !noautofill) && !noautofill)
...@@ -530,6 +516,9 @@ internal_self_insert (int c, int noautofill) ...@@ -530,6 +516,9 @@ internal_self_insert (int c, int noautofill)
call0 (Vblink_paren_function); call0 (Vblink_paren_function);
hairy = 2; hairy = 2;
} }
/* Run hooks for electric keys. */
call1 (Vrun_hooks, Qpost_self_insert_hook);
return hairy; return hairy;
} }
...@@ -550,15 +539,13 @@ syms_of_cmds (void) ...@@ -550,15 +539,13 @@ syms_of_cmds (void)
Qexpand_abbrev = intern_c_string ("expand-abbrev"); Qexpand_abbrev = intern_c_string ("expand-abbrev");
staticpro (&Qexpand_abbrev); staticpro (&Qexpand_abbrev);
DEFVAR_LISP ("self-insert-face", &Vself_insert_face, Qpost_self_insert_hook = intern_c_string ("post-self-insert-hook");
doc: /* If non-nil, set the face of the next self-inserting character to this. staticpro (&Qpost_self_insert_hook);
See also `self-insert-face-command'. */);
Vself_insert_face = Qnil;
DEFVAR_LISP ("self-insert-face-command", &Vself_insert_face_command, DEFVAR_LISP ("post-self-insert-hook", &Vpost_self_insert_hook,
doc: /* This is the command that set up `self-insert-face'. doc: /* Hook run at the end of `self-insert-command'.
If `last-command' does not equal this value, we ignore `self-insert-face'. */); This run is run after inserting the charater. */);
Vself_insert_face_command = Qnil; Vpost_self_insert_hook = Qnil;
DEFVAR_LISP ("blink-paren-function", &Vblink_paren_function, DEFVAR_LISP ("blink-paren-function", &Vblink_paren_function,
doc: /* Function called, if non-nil, whenever a close parenthesis is inserted. doc: /* Function called, if non-nil, whenever a close parenthesis is inserted.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment