auctex / etc / alphanum.el

;;; alphanum.el --- AUCTeX style for `alphanum.sty'

;; Copyright (C) 2004 Free Software Foundation, Inc.

;; Author: Frank Küster <frank@kuesterei.ch>
;; Maintainer: auctex-devel@gnu.org
;; Keywords: tex

;; This file is part of AUCTeX.

;; AUCTeX is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; AUCTeX is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with AUCTeX; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.

;;; Commentary:

;; This is file alphanum.el, which makes AUCTeX usable with jura.cls
;; and its style file alphanum.sty.
;;
;; Contributed by Frank Küster <frank@kuesterei.ch>. The code for
;; reftex has been written by Carsten Dominik, the maintainer of
;; reftex, but all the errors are mine.

;;; Code:


(defun TeX-arg-none (arg)
  (insert " "))

(defun reftex-get-section-level-alphanum ()
  (save-excursion			; preserve position
    (save-match-data		 ; preserve matching data (important!)
      ;; Go back to the beginning of the sectioning command
      (goto-char (match-beginning 0))
      ;; Define an initial level number, depending on the current macro.
      (let* ((macro (reftex-match-string 3))	  ; "toc" or "sub"
	     (lev (cond ((string= macro "toc") 1) ; min level for "toc"
			((string= macro "sub") 2) ; min level for "sub"
			(t 0)))
	     ;; Make a regular expression which will match sectioning commands
	     ;; and the levelup macro.
	     (re (concat "\\(^[^%]*\\\\levelup\\>\\)"
			 "\\|"
			 "\\(" reftex-section-regexp "\\)")))
	;; Now parse backwards for all sectioning and levelup macros,
	;; and keep track of the relative level changes.
	(while (re-search-backward re nil t)
	  (cond
	   ((match-beginning 1)
	    ;; levelup matched, reduce level counter
	    (setq lev (1- lev)))
	   ((string= (reftex-match-string 4) "toc")
	    ;; a toc entry, nothing changes
	    )
	   ((string= (reftex-match-string 4) "sub")
	    ;; a sub entry, increase level counter
	    (setq lev (1+ lev)))))
	;; return the level
	lev))))

(TeX-add-style-hook
 "alphanum"
 (lambda ()
   (setq LaTeX-largest-level (LaTeX-section-level "chapter"))
   (TeX-add-symbols '("levelup" TeX-arg-none))
   (make-local-variable 'LaTeX-section-list)
   (setq LaTeX-section-list
	 '(("part" 0)
	   ;; the levels don't make sense with alphanum, I randomly chose 0...
	   ("toc" 0)
	   ("sub" 0)))
   (setq LaTeX-section-label
	 '(("part" . "part:")
	   ("toc" . "sec:")
	   ("sub" . "sec:")))
   ;;
   ;; ****************** reftex part ******************
   ;; this won't work in multifile documents, but at least there is
   ;; something.

   (if (fboundp 'reftex-add-section-levels)
       (reftex-add-section-levels
	'(("toc" .  reftex-get-section-level-alphanum)
	  ("sub" .  reftex-get-section-level-alphanum))))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.