Function: bib-display-this-environment
bib-display-this-environment is a byte-compiled function defined in
bib-cite.el.
Signature
(bib-display-this-environment)
Documentation
Display the environment associated with a label, or its section name.
Assumes point is already on the label. Does not save excursion.
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/bib-cite.el
(defun bib-display-this-environment ()
"Display the environment associated with a label, or its section name.
Assumes point is already on the label.
Does not save excursion."
;; Bugs: The method used here to detect the environment is *not* foolproof.
;; It will get confused, for example, between two figure environments,
;; picking out both instead of the section label above them. But since
;; users typically puts their labels next to the section declaration,
;; I'm satisfied with this... for now.
;; I could have used the following AUCTeX functions:
;; LaTeX-current-environment
;; Function: Return the name (a string) of the enclosing LaTeX environment.
;; LaTeX-current-section
;; Function: Return the level of the section that contain point.
;; but then this code would only work as part of AUCTeX...
(let ((the-point (point))
(end-point (point))
(the-environment)(foundf))
(while (and (not foundf)
(goto-char end-point) ;Past end of last search
(re-search-forward "\\(^\\|\^M\\)[ \t]*\\\\end{\\([^}]*\\)}"
nil t))
(setq end-point (point))
(setq the-environment (match-string 2))
(and (not (string-match "document" the-environment))
(re-search-backward (concat "\\(^\\|\^M\\)[ \t]*\\\\begin{"
(regexp-quote the-environment) "}"))
(<= (point) the-point)
(setq foundf t)))
(if foundf ;A good environment
(progn
(cond ((bib-Is-hidden) ;Better way is: replace-within-string
(with-output-to-temp-buffer "*BiBTemp*"
(princ (buffer-substring (point) end-point)))
(set-buffer "*BiBTemp*")
(while (search-forward "\^M" nil t)
(replace-match "\n" nil t))
(goto-char 1)
(if (looking-at "\n") ;Remove first empty line...
(delete-char 1))
(with-output-to-temp-buffer "*Help*"
(princ (buffer-substring 1 (point-max))))
(kill-buffer "*BiBTemp*"))
(t
(with-output-to-temp-buffer "*Help*"
(princ (buffer-substring (point) end-point)))))
(bib-cite-fontify-help-as-latex))
;; Just find the section declaration
(goto-char the-point)
(if (re-search-backward
;;; "\\(^\\|\^M\\)[ \t]*\\\\\\(sub\\)*section{\\([^}]*\\)}" nil t)
;;; Michael Steiner <steiner@cs.uni-sb.de> patch
"\\(^\\|\^M\\)[ \t]*\\\\\\(\\(sub\\)*section\\|chapter\\|part\\)\\*?\
{\\([^}]*\\)}"
nil t)
(message (match-string 0))
(error
"Sorry, could not find an environment or section declaration")))))