Function: antlr-insert-option
antlr-insert-option is an interactive and byte-compiled function
defined in antlr-mode.el.gz.
Signature
(antlr-insert-option LEVEL OPTION &optional LOCATION)
Documentation
Insert file/grammar/rule/subrule option near point.
LEVEL determines option kind to insert: 1=file, 2=grammar, 3=rule,
4=subrule. OPTION is a string with the name of the option to insert.
LOCATION can be specified for not calling antlr-option-kind twice.
Inserting an option with this command works as follows:
1. When called interactively, LEVEL is determined by the prefix
argument or automatically deduced without prefix argument.
2. Signal an error if no option of that level could be inserted, e.g.,
if the buffer is read-only, the option area is outside the visible
part of the buffer or a subrule/rule option should be inserted with
point outside a subrule/rule.
3. When called interactively, OPTION is read from the minibuffer with
completion over the known options of the given LEVEL.
4. Ask user for confirmation if the given OPTION does not seem to be a
valid option to insert into the current file.
5. Find a correct position to insert the option.
6. Depending on the option, insert it the following way (inserting an
option also means inserting the option section if necessary):
- Insert the option and let user insert the value at point.
- Read a value (with completion) from the minibuffer, using a
previous value as initial contents, and insert option with value.
7. Final action depending on the option. For example, set the language
according to a newly inserted language option.
The name of all options with a specification for their values are stored
in antlr-options-alists which depends on antlr-tool-version.
If the option already exists inside the visible part of the buffer, this command can be used to change the value of that option. Otherwise, find a correct position where the option can be inserted near point.
The search for a correct position is as follows:
* If search is within an area where options can be inserted, use the
position of point. Inside the options section and if point is in
the middle of an option definition, skip the rest of it.
* If an options section already exists, insert the options at the end.
If only the beginning of the area is visible, insert at the
beginning.
* Otherwise, find the position where an options section can be
inserted and insert a new section before any comments. If the
position before the comments is not visible, insert the new section
after the comments.
This function also inserts "options {...}" and the ":" if necessary,
see antlr-options-auto-colon. See also antlr-options-assign-string.
This command might also set the mark like C-SPC (set-mark-command) does, see
antlr-options-push-mark.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/antlr-mode.el.gz
;;;===========================================================================
;;; Insert option: command
;;;===========================================================================
(defun antlr-insert-option (level option &optional location)
"Insert file/grammar/rule/subrule option near point.
LEVEL determines option kind to insert: 1=file, 2=grammar, 3=rule,
4=subrule. OPTION is a string with the name of the option to insert.
LOCATION can be specified for not calling `antlr-option-kind' twice.
Inserting an option with this command works as follows:
1. When called interactively, LEVEL is determined by the prefix
argument or automatically deduced without prefix argument.
2. Signal an error if no option of that level could be inserted, e.g.,
if the buffer is read-only, the option area is outside the visible
part of the buffer or a subrule/rule option should be inserted with
point outside a subrule/rule.
3. When called interactively, OPTION is read from the minibuffer with
completion over the known options of the given LEVEL.
4. Ask user for confirmation if the given OPTION does not seem to be a
valid option to insert into the current file.
5. Find a correct position to insert the option.
6. Depending on the option, insert it the following way (inserting an
option also means inserting the option section if necessary):
- Insert the option and let user insert the value at point.
- Read a value (with completion) from the minibuffer, using a
previous value as initial contents, and insert option with value.
7. Final action depending on the option. For example, set the language
according to a newly inserted language option.
The name of all options with a specification for their values are stored
in `antlr-options-alists' which depends on `antlr-tool-version'.
If the option already exists inside the visible part of the buffer, this
command can be used to change the value of that option. Otherwise, find
a correct position where the option can be inserted near point.
The search for a correct position is as follows:
* If search is within an area where options can be inserted, use the
position of point. Inside the options section and if point is in
the middle of an option definition, skip the rest of it.
* If an options section already exists, insert the options at the end.
If only the beginning of the area is visible, insert at the
beginning.
* Otherwise, find the position where an options section can be
inserted and insert a new section before any comments. If the
position before the comments is not visible, insert the new section
after the comments.
This function also inserts \"options {...}\" and the \":\" if necessary,
see `antlr-options-auto-colon'. See also `antlr-options-assign-string'.
This command might also set the mark like \\[set-mark-command] does, see
`antlr-options-push-mark'."
(interactive (antlr-insert-option-interactive current-prefix-arg))
(barf-if-buffer-read-only)
(or location (setq location (cdr (antlr-option-kind level))))
(cond ((null level)
;; TODO: better msg if there is (currently) no such option
(error "Cannot deduce what kind of option to insert"))
((atom location)
(error "Cannot insert any %s options around here"
(elt antlr-options-headings (1- level)))))
(let ((area (car location))
(place (cdr location)))
(cond ((null place) ; invisible
(error (if area
"Invisible %s options, use %s to make them visible"
"Invisible area for %s options, use %s to make it visible")
(elt antlr-options-headings (1- level))
(substitute-command-keys "\\[widen]")))
((null area) ; without option part
(antlr-insert-option-do level option nil
(null (cdr place))
(car place)))
((save-excursion ; with option part, option visible
(goto-char (max (point-min) (car area)))
(re-search-forward (concat "\\(^\\|;\\)[ \t]*\\(\\<"
(regexp-quote option)
"\\_>\\)[ \t\n]*\\(\\(=[ \t]?\\)[ \t]*\\(\\(\\sw\\|\\s_\\)+\\|\"\\([^\n\"\\]\\|[\\][^\n]\\)*\"\\)?\\)?")
;; 2=name, 3=4+5, 4="=", 5=value
(min (point-max) (cdr area))
t))
(antlr-insert-option-do level option
(cons (or (match-beginning 5)
(match-beginning 3))
(match-end 5))
(and (null (cdr place)) area)
(or (match-beginning 5)
(match-end 4)
(match-end 2))))
(t ; with option part, option not yet
(antlr-insert-option-do level option t
(and (null (cdr place)) area)
(car place))))))