(require (quote BibTeX-mode)) (defconst bibtex-bib-ext ".bib") (defconst bibtex-abbrev-ext ".abv") (defvar bibtex-gabbrev-evaled nil "\ Flag which is set t if default group abbrev has been evaluated") (defvar bibtex-fabbrev-evaled nil "\ Flag which is set t if default field abbrev has been evaluated") (defvar bibtex-gabbrev nil "\ List of group abbrev names") (defvar bibtex-fabbrev nil "\ List of field abbrev names") (defvar bibtex-abbrev-internal nil "\ List of files that have been read") (defconst bibtex-browse-prompt (quote (((13 121) "RET" yes) ((27) "ESC" yes-abbrev) ((32 110) "SPC" next) ((127 112) "DEL" previous) ((115) "s" show) ((103) "g" goto) ((102) "f" new-file) ((18) "C-r" redit) ((63) "?=help" help))) "\ Data for abbreviation browsing prompt") (defun bibtex-make-gabbrev (start end name) (interactive "r sGroup abbrev name: ") (byte-code "ʈ \"!f \" ! \"P!!b ` b `\" !c $ \") !+ \")" [case-fold-search t name grp fnnd abvbuf default-directory bibtex-abbrev-ext start end nil string-equal "" error "Can't accept null name...try again" message "Defining group abbreviation `%s'..." file-name-nondirectory buffer-file-name get-buffer-create bibtex-fn-w-ext beginning-of-line end-of-line buffer-substring bibtex-current-entry previous-line 1 " %GROUP(" insert ", " " ) " bibtex-scan-gabbrev kill-buffer "Defining group abbreviation `%s'...done"] 19)) (defun bibtex-insert-gabbrev (sym) (interactive "SGroup abbrev name (default browsing mode): ") (byte-code "Lj ! !\"; ! 4@87lj)@ N ^nMǂS! c\"b \"," [name sym fn case-fold-search t cont pair nil symbol-name buffer-file-name message "Inserting group abbreviation..." string-equal "" bibtex-eval-gabbrev bibtex-browse-gabbrev 1 group next-line beginning-of-line "Inserting group abbreviation `%s'...done" bibtex-read-file] 12)) (defun bibtex-browse-gabbrev nil (byte-code " !ʍ-" [=prev= nil =curr= bibtex-gabbrev =buff= =name= =cont= get-buffer-create "--- BibTeX Abbreviation ---" exit (byte-code "+@ !N BA !$ " [=curr= =name= =cont= =prev= =buff= intern group get-buffer-window bibtex-show-abbrev bibtex-browse-cmd] 6)] 6)) (defun bibtex-browse-cmd (&optional fld) (byte-code " Q \"ɍ*" [cmd =name= bibtex-browse-prompt win vortex-user-response "Confirm `" "' " nil done (byte-code "x = ! ! E\"t =< !1 ! E\"t =qKƂi!UƂi!!!Ɖ\"t =A@ BBA!Ƃ!! B!@CA\"t = Q \"t =B!    *@   \"\"& BA@CA\"*t =RƉ\"t =l! Q \"t =t" [t cmd win =buff= =name= =cont= nil =curr= =prev= bibtex-browse-prompt key grp fld bibtex-fabbrev bibtex-gabbrev yes get-buffer-window delete-window throw exit yes-abbrev next y-or-n-p "Can't find next abbreviation, exit? " message "Wrapping around..." sit-for 1 reverse done previous "Can't find previous abbreviation, exit? " show bibtex-show-abbrev vortex-user-response "Confirm `" "' " goto read-string "Goto key: " string-lessp new-file redit "Entering recursive edit...use ESC C-c to return" recursive-edit help ((byte-code " Q \"" [cmd =name= bibtex-browse-prompt bibtex-browse-help vortex-user-response "Confirm `" "' "] 5))] 30)] 4)) (defun bibtex-show-abbrev nil (byte-code "! $b!" [=buff= =name= =cont= pop-to-buffer erase-buffer insert "Abbreviation: " " " 1 other-window] 7)) (defun bibtex-browse-help nil (byte-code "! Veb!eb!" [pop-to-buffer "--- BibTeX Abbreviation Help ---" buffer-size 0 insert-string "RET or `y' -- Confirm and exit, the abbreviated text is inserted. ESC -- Confirm and exit, only the abbreviation is inserted (FIELD ABBREV ONLY). SPC -- Ignore current abbreviation. Advance to the next. DEL -- Ignore current abbreviation. Go back to the previous. `s' -- Show the content of current abbreviation in the other window. `g' -- Go to the abbreviation whose name is greater than the specified key. `f' -- Not in current list of abbreviations. Read more from a new file. C-r -- Enrter recursive edit. Return to browsing by ESC C-c. `?' -- This help message." other-window 1] 5)) (defun bibtex-read-file (sym name &optional field) (byte-code " ɂ \"͂ QR!Dҍ 4Ԃ5\" = !Q N!Q!+" [msg fn tmp field name sym "Load file (default path TEXBIB): " nil y-or-n-p "Field" "Group" " abbreviations" string-equal "" " `" "'" " not found, read from another file? " ok (byte-code "H ! \" 8 \"1 Q!*Ƃ.\"5\"D #!" [t fn tmp msg bibtex-path bibtex-abbrev-internal nil vortex-file-exists-p read-string vortex-memq ding y-or-n-p "Abbreviations in \"" "\" have been read, try another file? " throw ok message "%s%s...not found, try again" sit-for 2] 13) bibtex-load-abbrev "field" "group" bibtex-insert-fabbrev bibtex-insert-gabbrev message "Browsing field abbreviations...abort" "Inserting group abbreviation...abort"] 8)) (defun bibtex-eval-gabbrev (fn) (byte-code "% %  @\" Aĉ) 0\"7@\"ĉ" [bibtex-gabbrev-evaled nil bibtex-abbrev-files lst t bibtex-require-local-eval fn bibtex-abbrev-internal bibtex-load-abbrev "group" vortex-memq] 5)) (defun bibtex-insert-fabbrev nil (interactive) (byte-code "ƈ !!  G @ 8 89 c \"D c! \"L#-" [fn case-fold-search t pair name cont nil buffer-file-name message "Browsing field abbreviations..." bibtex-eval-fabbrev bibtex-browse-fabbrev 1 2 "Browsing field abbreviations...done (`%s' text inserted)" bibtex-erase-delimiters "Browsing field abbreviations...done (`%s' inserted)" bibtex-read-file ""] 11)) (defun bibtex-browse-fabbrev nil (byte-code " !ʍ-" [=prev= nil =curr= bibtex-fabbrev =buff= =name= =cont= get-buffer-create "--- BibTeX Abbreviation ---" exit (byte-code ",@ !N BA !$ !" [=curr= =name= =cont= =prev= =buff= t intern field get-buffer-window bibtex-show-abbrev bibtex-browse-cmd] 6)] 6)) (defun bibtex-eval-fabbrev (fn) (byte-code "% %  @\" Aĉ) 0\"7<\"ĉ" [bibtex-fabbrev-evaled nil bibtex-abbrev-files lst t bibtex-require-local-eval fn bibtex-abbrev-internal bibtex-load-abbrev "field" vortex-memq] 5)) (defun bibtex-fn-w-ext (fn suffix) "\ Attach SUFFIX to the base of FN, if FN has no extension or has extension `.bib' or `.abv'. Otherwise (i.e FN has other extension) FN itself is returned." (byte-code " \"Ă& \"Ă& \"&ĉ 4 O P5 *" [base fn ext-set t nil suffix string-match "\\.bib" "\\.abv" "\\." 0] 6)) (defun bibtex-load-abbrev (fn &optional type) "\ Load abbreviations from file FN. Load both types of abbrev is TYPE is nil; otherwise load only TYPE." (interactive "FLoad abbreviations, file name base: ") (byte-code "Ɉ ! \"\"\"=!\"!\" \"= #+" [abv fn bibtex-abbrev-ext case-fold-search t bib bibtex-path type bibtex-bib-ext nil bibtex-fn-w-ext expand-file-name vortex-file-exists-p bibtex-read-abbrev message "\"%s\" (compiled abbreviations) not found" file-name-nondirectory sit-for 2 bibtex-save-abbrev] 13)) (defun bibtex-read-abbrev (abv type) "\ Read a .abv file. Each entry in this file is TYPE (i.e. either field or group) NAME TEXT. If TYPE is nil, read both types, else read only the specified type." (byte-code " ! !  P # Bqb #@ \"-! #)," [abvbuf abv fnnd type key bibtex-abbrev-internal nil t find-file-noselect file-name-nondirectory "" "^" "\\w" message "Loading %s abbreviations from file \"%s\"..." 1 re-search-forward beginning-of-line bibtex-scan-abbrev kill-buffer "Loading %s abbreviations from file \"%s\"...done"] 11)) (defun bibtex-scan-abbrev (fnnd abvbuf) (byte-code " != ! # ! ! !!*" [field abvbuf name fnnd read message "Loading abbreviations from file \"%s\", doing `%s'..." bibtex-add-fabbrev bibtex-add-gabbrev eval] 8)) (defun bibtex-save-abbrev (&optional fn &optional abv &optional check) "\ Compile abbreviations, pull them up to the beginning of the file, convert them into Emacs Lisp objects, and save them in the a .abv file. If the optional CHECK is non-nil, ask the user if it has already been compiled." (interactive) (byte-code "Ȉ! !  \"P!qb#) @ ?@! b #X `SYd !!  \" q )b#!fU  \"  \"@ V8\"\" bc` ) qd %) ! \". ȂƉ )!' !# P&!)," [fn fnnd abv default-directory bibtex-abbrev-ext case-fold-search t bibtex-abbrev-match-fg nil check bibtex-require-local-eval base bibtex-entry-no-group-match abvbuf abbrev boa eoa astring shell-file-name message "Compiling abbreviations..." buffer-file-name file-name-nondirectory bibtex-fn-w-ext find-file-noselect 1 re-search-forward y-or-n-p "Abbreviations already compiled, overwrite? " beginning-of-line get-buffer-create "Compiling abbreviations...(doing \"%s\")" erase-buffer match-beginning 0 64 bibtex-scan-fabbrev bibtex-scan-gabbrev buffer-substring delete-region write-region no-message kill-buffer "Compiling abbreviations...done (saved in %s)" "Compiling abbreviations...quit" file-exists-p call-process "-c" "\\rm " "Compiling abbreviations...done (no abbreviations compiled)"] 32)) (defun bibtex-scan-fabbrev (fnnd abvbuf) (byte-code " 888 88 # b q ! ! # &)," [abbrev name end text fnnd abvbuf bibtex-current-field 2 3 1 bibtex-next-field message "Compiling abbreviations in file \"%s\", doing `%s'..." bibtex-add-fabbrev put intern field insert "field \"" "\" " "(put '" " 'field \"" "\") "] 15)) (defun bibtex-add-fabbrev (name) (byte-code " ƍ! \"+" [head nil tail bibtex-fabbrev field ok (byte-code "7@ \"\"3 \") B\"3 BA B" [tail field name t head nil string-equal throw ok string-lessp] 8) append reverse] 4)) (defun bibtex-scan-gabbrev (fnnd abvbuf) (byte-code "!88\\8Z88 \" # bq ! # &)!!c)-" [abbrev t bog eog name string fnnd abvbuf bibtex-current-entry 1 3 2 buffer-substring message "Compiling abbreviations in file \"%s\", doing `%s'..." bibtex-add-gabbrev insert "group \"" "\" " "(put '" " 'group " "\"" " \")" eval read " "] 12)) (defun bibtex-add-gabbrev (name) (byte-code " ƍ! \"+" [head nil tail bibtex-gabbrev grp ok (byte-code "7@ \"\"3 \") B\"3 BA B" [tail grp name t head nil string-equal throw ok string-lessp] 8) append reverse] 4))