mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-16 02:50:26 -08:00
(local-variables-section): Adapted comment to outline minor mode.
(skeleton-pair-insert-maybe): Rewritten to support autowrapping. (mirror-mode): Fixed change of pair-* to skeleton-pair-*. Also pairs 8 bit characters.
This commit is contained in:
parent
4d123b4d43
commit
ff85d4f3be
1 changed files with 83 additions and 82 deletions
165
lisp/skeleton.el
165
lisp/skeleton.el
|
|
@ -126,7 +126,7 @@ INTERACTOR and ELEMENT ... are as defined under `skeleton-insert'."
|
||||||
(defun skeleton-proxy (&optional str arg)
|
(defun skeleton-proxy (&optional str arg)
|
||||||
"Insert skeleton defined by variable of same name (see `skeleton-insert').
|
"Insert skeleton defined by variable of same name (see `skeleton-insert').
|
||||||
Prefix ARG allows wrapping around words or regions (see `skeleton-insert').
|
Prefix ARG allows wrapping around words or regions (see `skeleton-insert').
|
||||||
If no ARG was given, and the region is visible, it defaults to -1 depending
|
If no ARG was given, but the region is visible, ARG defaults to -1 depending
|
||||||
on `skeleton-autowrap'. An ARG of M-0 will prevent this just for once.
|
on `skeleton-autowrap'. An ARG of M-0 will prevent this just for once.
|
||||||
This command can also be an abbrev expansion (3rd and 4th columns in
|
This command can also be an abbrev expansion (3rd and 4th columns in
|
||||||
\\[edit-abbrevs] buffer: \"\" command-name).
|
\\[edit-abbrevs] buffer: \"\" command-name).
|
||||||
|
|
@ -158,7 +158,7 @@ ignored."
|
||||||
(and skeleton-autowrap
|
(and skeleton-autowrap
|
||||||
(or (eq last-command 'mouse-drag-region)
|
(or (eq last-command 'mouse-drag-region)
|
||||||
(and transient-mark-mode mark-active))
|
(and transient-mark-mode mark-active))
|
||||||
-1)))
|
-1)))
|
||||||
(if (stringp str)
|
(if (stringp str)
|
||||||
str))
|
str))
|
||||||
(and skeleton-abbrev-cleanup
|
(and skeleton-abbrev-cleanup
|
||||||
|
|
@ -396,32 +396,32 @@ automatically, and you are prompted to fill in the variable parts.")))
|
||||||
|
|
||||||
|
|
||||||
;; Maybe belongs into simple.el or elsewhere
|
;; Maybe belongs into simple.el or elsewhere
|
||||||
|
;; ;###autoload
|
||||||
;;;(define-skeleton local-variables-section
|
;;; (define-skeleton local-variables-section
|
||||||
;;; "Insert a local variables section. Use current comment syntax if any."
|
;; "Insert a local variables section. Use current comment syntax if any."
|
||||||
;;; (completing-read "Mode: " obarray
|
;; (completing-read "Mode: " obarray
|
||||||
;;; (lambda (symbol)
|
;; (lambda (symbol)
|
||||||
;;; (if (commandp symbol)
|
;; (if (commandp symbol)
|
||||||
;;; (string-match "-mode$" (symbol-name symbol))))
|
;; (string-match "-mode$" (symbol-name symbol))))
|
||||||
;;; t)
|
;; t)
|
||||||
;;; '(save-excursion
|
;; '(save-excursion
|
||||||
;;; (if (re-search-forward page-delimiter nil t)
|
;; (if (re-search-forward page-delimiter nil t)
|
||||||
;;; (error "Not on last page.")))
|
;; (error "Not on last page.")))
|
||||||
;;; comment-start "Local Variables:" comment-end \n
|
;; comment-start "Local Variables:" comment-end \n
|
||||||
;;; comment-start "mode: " str
|
;; comment-start "mode: " str
|
||||||
;;; & -5 | '(kill-line 0) & -1 | comment-end \n
|
;; & -5 | '(kill-line 0) & -1 | comment-end \n
|
||||||
;;; ( (completing-read (format "Variable, %s: " skeleton-subprompt)
|
;; ( (completing-read (format "Variable, %s: " skeleton-subprompt)
|
||||||
;;; obarray
|
;; obarray
|
||||||
;;; (lambda (symbol)
|
;; (lambda (symbol)
|
||||||
;;; (or (eq symbol 'eval)
|
;; (or (eq symbol 'eval)
|
||||||
;;; (user-variable-p symbol)))
|
;; (user-variable-p symbol)))
|
||||||
;;; t)
|
;; t)
|
||||||
;;; comment-start str ": "
|
;; comment-start str ": "
|
||||||
;;; (read-from-minibuffer "Expression: " nil read-expression-map nil
|
;; (read-from-minibuffer "Expression: " nil read-expression-map nil
|
||||||
;;; 'read-expression-history) | _
|
;; 'read-expression-history) | _
|
||||||
;;; comment-end \n)
|
;; comment-end \n)
|
||||||
;;; resume:
|
;; resume:
|
||||||
;;; comment-start "End:" comment-end)
|
;; comment-start "End:" comment-end)
|
||||||
|
|
||||||
;; Variables and command for automatically inserting pairs like () or "".
|
;; Variables and command for automatically inserting pairs like () or "".
|
||||||
|
|
||||||
|
|
@ -452,78 +452,79 @@ Elements might be (?` ?` _ \"''\"), (?\\( ? _ \" )\") or (?{ \\n > _ \\n ?} >).
|
||||||
(defun skeleton-pair-insert-maybe (arg)
|
(defun skeleton-pair-insert-maybe (arg)
|
||||||
"Insert the character you type ARG times.
|
"Insert the character you type ARG times.
|
||||||
|
|
||||||
With no ARG, if `skeleton-pair' is non-nil, and if
|
With no ARG, if `skeleton-pair' is non-nil, pairing can occur. If the region
|
||||||
`skeleton-pair-on-word' is non-nil or we are not before or inside a
|
is visible the pair is wrapped around it depending on `skeleton-autowrap'.
|
||||||
|
Else, if `skeleton-pair-on-word' is non-nil or we are not before or inside a
|
||||||
word, and if `skeleton-pair-filter' returns nil, pairing is performed.
|
word, and if `skeleton-pair-filter' returns nil, pairing is performed.
|
||||||
|
|
||||||
If a match is found in `skeleton-pair-alist', that is inserted, else
|
If a match is found in `skeleton-pair-alist', that is inserted, else
|
||||||
the defaults are used. These are (), [], {}, <> and `' for the
|
the defaults are used. These are (), [], {}, <> and `' for the
|
||||||
symmetrical ones, and the same character twice for the others."
|
symmetrical ones, and the same character twice for the others."
|
||||||
(interactive "*P")
|
(interactive "*P")
|
||||||
(if (or arg
|
(let ((mark (and skeleton-autowrap
|
||||||
overwrite-mode
|
(or (eq last-command 'mouse-drag-region)
|
||||||
(not skeleton-pair)
|
(and transient-mark-mode mark-active))))
|
||||||
(if (not skeleton-pair-on-word) (looking-at "\\w"))
|
(skeleton-end-hook))
|
||||||
(funcall skeleton-pair-filter))
|
(if (or arg
|
||||||
(self-insert-command (prefix-numeric-value arg))
|
(not skeleton-pair)
|
||||||
(self-insert-command 1)
|
(and (not mark)
|
||||||
(if skeleton-abbrev-cleanup
|
(or overwrite-mode
|
||||||
()
|
(if (not skeleton-pair-on-word) (looking-at "\\w"))
|
||||||
;; (preceding-char) is stripped of any Meta-stuff in last-command-char
|
(funcall skeleton-pair-filter))))
|
||||||
(if (setq arg (assq (preceding-char) skeleton-pair-alist))
|
(self-insert-command (prefix-numeric-value arg))
|
||||||
;; typed char is inserted (car is no real interactor)
|
(setq last-command-char (logand last-command-char 255))
|
||||||
(let (skeleton-end-hook)
|
(or skeleton-abbrev-cleanup
|
||||||
(skeleton-insert arg))
|
(skeleton-insert
|
||||||
(save-excursion
|
(cons nil (or (assq last-command-char skeleton-pair-alist)
|
||||||
(insert (or (cdr (assq (preceding-char)
|
(assq last-command-char '((?( _ ?))
|
||||||
'((?( . ?))
|
(?[ _ ?])
|
||||||
(?[ . ?])
|
(?{ _ ?})
|
||||||
(?{ . ?})
|
(?< _ ?>)
|
||||||
(?< . ?>)
|
(?` _ ?')))
|
||||||
(?` . ?'))))
|
`(,last-command-char _ ,last-command-char)))
|
||||||
last-command-char)))))))
|
(if mark -1))))))
|
||||||
|
|
||||||
|
|
||||||
;;; A more serious example can be found in sh-script.el
|
;; A more serious example can be found in sh-script.el
|
||||||
;;;(defun mirror-mode ()
|
;;; (defun mirror-mode ()
|
||||||
;; "This major mode is an amusing little example of paired insertion.
|
;; "This major mode is an amusing little example of paired insertion.
|
||||||
;;All printable characters do a paired self insert, while the other commands
|
;;All printable characters do a paired self insert, while the other commands
|
||||||
;;work normally."
|
;;work normally."
|
||||||
;; (interactive)
|
;; (interactive)
|
||||||
;; (kill-all-local-variables)
|
;; (kill-all-local-variables)
|
||||||
;; (make-local-variable 'pair)
|
;; (make-local-variable 'skeleton-pair)
|
||||||
;; (make-local-variable 'pair-on-word)
|
;; (make-local-variable 'skeleton-pair-on-word)
|
||||||
;; (make-local-variable 'pair-filter)
|
;; (make-local-variable 'skeleton-pair-filter)
|
||||||
;; (make-local-variable 'pair-alist)
|
;; (make-local-variable 'skeleton-pair-alist)
|
||||||
;; (setq major-mode 'mirror-mode
|
;; (setq major-mode 'mirror-mode
|
||||||
;; mode-name "Mirror"
|
;; mode-name "Mirror"
|
||||||
;; pair-on-word t
|
;; skeleton-pair-on-word t
|
||||||
;; ;; in the middle column insert one or none if odd window-width
|
;; ;; in the middle column insert one or none if odd window-width
|
||||||
;; pair-filter (lambda ()
|
;; skeleton-pair-filter (lambda ()
|
||||||
;; (if (>= (current-column)
|
;; (if (>= (current-column)
|
||||||
;; (/ (window-width) 2))
|
;; (/ (window-width) 2))
|
||||||
;; ;; insert both on next line
|
;; ;; insert both on next line
|
||||||
;; (next-line 1)
|
;; (next-line 1)
|
||||||
;; ;; insert one or both?
|
;; ;; insert one or both?
|
||||||
;; (= (* 2 (1+ (current-column)))
|
;; (= (* 2 (1+ (current-column)))
|
||||||
;; (window-width))))
|
;; (window-width))))
|
||||||
;; ;; mirror these the other way round as well
|
;; ;; mirror these the other way round as well
|
||||||
;; pair-alist '((?) _ ?()
|
;; skeleton-pair-alist '((?) _ ?()
|
||||||
;; (?] _ ?[)
|
;; (?] _ ?[)
|
||||||
;; (?} _ ?{)
|
;; (?} _ ?{)
|
||||||
;; (?> _ ?<)
|
;; (?> _ ?<)
|
||||||
;; (?/ _ ?\\)
|
;; (?/ _ ?\\)
|
||||||
;; (?\\ _ ?/)
|
;; (?\\ _ ?/)
|
||||||
;; (?` ?` _ "''")
|
;; (?` ?` _ "''")
|
||||||
;; (?' ?' _ "``"))
|
;; (?' ?' _ "``"))
|
||||||
;; ;; in this mode we exceptionally ignore the user, else it's no fun
|
;; ;; in this mode we exceptionally ignore the user, else it's no fun
|
||||||
;; pair t)
|
;; skeleton-pair t)
|
||||||
;; (let ((map (make-keymap))
|
;; (let ((map (make-vector 256 'skeleton-pair-insert-maybe))
|
||||||
;; (i ? ))
|
;; (i 0))
|
||||||
;; (use-local-map map)
|
;; (use-local-map `(keymap ,map))
|
||||||
;; (setq map (car (cdr map)))
|
;; (while (< i ? )
|
||||||
;; (while (< i ?\^?)
|
;; (aset map i nil)
|
||||||
;; (aset map i 'skeleton-pair-insert-maybe)
|
;; (aset map (+ i 128) nil)
|
||||||
;; (setq i (1+ i))))
|
;; (setq i (1+ i))))
|
||||||
;; (run-hooks 'mirror-mode-hook))
|
;; (run-hooks 'mirror-mode-hook))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue