;;; srecode/fields.el --- Handling type-in fields in a buffer.
;;
-;; Copyright (C) 2009 Free Software Foundation, Inc.
+;; Copyright (C) 2009-2011 Free Software Foundation, Inc.
;;
;; Author: Eric M. Ludlam <eric@siege-engine.com>
;; Each field has 2 overlays. The second overlay allows control in
;; the character just after the field, but does not highlight it.
+;; @TODO - Cancel an old field array if a new one is about to be created!
+
;; Keep this library independent of SRecode proper.
(require 'eieio)
"While inserting a set of fields, collect in this variable.
Once an insertion set is done, these fields will be activated.")
+\f
+;;; Customization
+;;
+
(defface srecode-field-face
'((((class color) (background dark))
(:underline "green"))
"*Face used to specify editable fields from a template."
:group 'semantic-faces)
+(defcustom srecode-fields-exit-confirmation nil
+ "Ask for confirmation before leaving field editing mode."
+ :group 'srecode
+ :type 'boolean)
+
;;; BASECLASS
;;
;; Fields and the template region share some basic overlay features.
))
;; Create a temporary overlay now. We have to use an overlay and
- ;; not a marker becaues of the in-front insertion rules. The rules
+ ;; not a marker because of the in-front insertion rules. The rules
;; are backward from what is wanted while typing.
(setq olay (make-overlay start end (current-buffer) t nil))
(overlay-put olay 'srecode-init-only t)
(oset ir fields srecode-field-archive)
(setq srecode-field-archive nil)
- ;; Initailize myself first.
+ ;; Initialize myself first.
(call-next-method)
)
(remove-hook 'post-command-hook 'srecode-field-post-command t)
(if (srecode-point-in-region-p ar)
nil ;; Keep going
- ;; We moved out of the temlate. Cancel the edits.
+ ;; We moved out of the template. Cancel the edits.
(srecode-delete ar)))
))
)
(defvar srecode-field-replication-max-size 100
- "Maximum size of a field before cancelling replication.")
+ "Maximum size of a field before canceling replication.")
(defun srecode-field-mod-hook (ol after start end &optional pre-len)
"Modification hook for the field overlay.
(inhibit-modification-hooks t)
)
;; Sometimes a field is deleted, but we might still get a stray
- ;; event. Lets just ignore those events.
+ ;; event. Let's just ignore those events.
(when (slot-boundp field 'overlay)
;; First, fixup the two overlays, in case they got confused.
(let ((main (oref field overlay))
(defun srecode-field-exit-ask ()
"Ask if the user wants to exit field-editing mini-mode."
(interactive)
- (when (y-or-n-p "Exit field-editing mode? ")
+ (when (or (not srecode-fields-exit-confirmation)
+ (y-or-n-p "Exit field-editing mode? "))
(srecode-delete (srecode-active-template-region))))