When I'm writing a php program I often face the following situation:
step 1: '[' pressed: Result: [<cursor> step 2: ']' pressed Result: <cursor> step 3: move the cursor between '': Result: [<cursor>]
My idea was to save 1 keystroke and do step 3 automatically when '' sequence was pressed.
Currently I did the following:
;flag to signal us the '[' was pressed (defvar *kb--bracket-pressed* nil) ;activate flag (defun bracket-pressed () "[ key pressed" (interactive) ;activate flag (setq *kb--bracket-pressed* t) (insert "[") ) (defun back-bracket-pressed () "] key pressed" (interactive) (when *kb--bracket-pressed* (insert "]") (backward-char 1) ;deactivate flag (setq *kb--bracket-pressed* nil) ) ) ;when php-mode is activated (local-set-key (kbd "[") 'bracket-pressed) (local-set-key (kbd "]") 'back-bracket-pressed)
The problem is: I don't know how to reset the flag to nil, when any other key except "]" was pressed after "[".