(defun bibtex-find-text-internal (&optional noerror subfield comma)
"Find text part of current BibTeX field or entry head.
-Return list (NAME START-TEXT END-TEXT END) with field or entry name,
-start and end of text and end of field or entry head, or nil if not found.
-If optional arg NOERROR is non-nil, an error message is suppressed if text
-is not found. If optional arg SUBFIELD is non-nil START-TEXT and END-TEXT
-correspond to the current subfield delimited by #.
+Return list (NAME START-TEXT END-TEXT END STRING-CONST) with field
+or entry name, start and end of text, and end of field or entry head.
+STRING-CONST is a flag which is non-nil if current subfield delimited by #
+is a BibTeX string constant. Return value is nil if field or entry head
+are not found.
+If optional arg NOERROR is non-nil, an error message is suppressed
+if text is not found. If optional arg SUBFIELD is non-nil START-TEXT
+and END-TEXT correspond to the current subfield delimited by #.
Optional arg COMMA is as in `bibtex-enclosing-field'."
(save-excursion
(let ((pnt (point))
(bounds (bibtex-enclosing-field comma t))
(case-fold-search t)
- name start-text end-text end failure done no-sub)
+ name start-text end-text end failure done no-sub string-const)
(bibtex-beginning-of-entry)
(cond (bounds
(setq name (bibtex-name-in-field bounds t)
(goto-char start-text)
(while (not done)
(if (or (prog1 (looking-at bibtex-field-const)
- (setq end-text (match-end 0)))
+ (setq end-text (match-end 0)
+ string-const t))
(prog1 (setq bounds (bibtex-parse-field-string))
- (setq end-text (cdr bounds))))
+ (setq end-text (cdr bounds)
+ string-const nil)))
(progn
(if (and (<= start-text pnt) (<= pnt end-text))
(setq done t)
(setq start-text (goto-char (match-end 0)))))
(setq done t failure t)))))
(cond ((not failure)
- (list name start-text end-text end))
+ (list name start-text end-text end string-const))
((and no-sub (not noerror))
(error "Not on text part of BibTeX field"))
((not noerror) (error "Not on BibTeX field"))))))
Optional arg COMMA is as in `bibtex-enclosing-field'. It is t for
interactive calls."
(interactive (list t))
- (let* ((bounds (bibtex-find-text-internal nil t comma))
- (start (nth 1 bounds))
- (end (nth 2 bounds)))
- (if (memq (char-before end) '(?\} ?\"))
- (delete-region (1- end) end))
- (if (memq (char-after start) '(?\{ ?\"))
- (delete-region start (1+ start)))))
+ (let ((bounds (bibtex-find-text-internal nil t comma)))
+ (unless (nth 4 bounds)
+ (delete-region (1- (nth 2 bounds)) (nth 2 bounds))
+ (delete-region (nth 1 bounds) (1+ (nth 1 bounds))))))
(defun bibtex-kill-field (&optional copy-only comma)
"Kill the entire enclosing BibTeX field.