Function: bibtex-style-calculate-indentation
bibtex-style-calculate-indentation is a byte-compiled function defined
in bibtex-style.el.gz.
Signature
(bibtex-style-calculate-indentation &optional VIRT)
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/bibtex-style.el.gz
(defun bibtex-style-calculate-indentation (&optional virt)
(or
;; Stick the first line at column 0.
(and (= (point-min) (line-beginning-position)) 0)
;; Commands start at column 0.
(and (looking-at (regexp-opt bibtex-style-commands 'words)) 0)
;; Trust the current indentation, if such info is applicable.
(and virt (save-excursion (skip-chars-backward " \t{") (bolp))
(current-column))
;; Put leading close-paren where the matching open brace would be.
(and (looking-at "}")
(condition-case nil
(save-excursion
(up-list -1)
(bibtex-style-calculate-indentation 'virt))
(scan-error nil)))
;; Align leading "if$" with previous command.
(and (looking-at "if\\$")
(condition-case nil
(save-excursion
(backward-sexp 3)
(bibtex-style-calculate-indentation 'virt))
(scan-error
;; There is no command before the "if$".
(condition-case nil
(save-excursion
(up-list -1)
(+ bibtex-style-indent-basic
(bibtex-style-calculate-indentation 'virt)))
(scan-error nil)))))
;; Right after an opening brace.
(condition-case err (save-excursion (backward-sexp 1) nil)
(scan-error (goto-char (nth 2 err))
(+ bibtex-style-indent-basic
(bibtex-style-calculate-indentation 'virt))))
;; Default, align with previous command.
(let ((fai ;; First arm of an "if$".
(condition-case nil
(save-excursion
(forward-sexp 2)
(forward-comment (point-max))
(looking-at "if\\$"))
(scan-error nil))))
(save-excursion
(condition-case nil
(while (progn
(backward-sexp 1)
(save-excursion (skip-chars-backward " \t{") (not (bolp)))))
(scan-error nil))
(+ (current-column)
(if (or fai (looking-at "ENTRY")) bibtex-style-indent-basic 0))))))