# NEdit Macros for BibTeX # # Version 1.0, tested with NEdit 5.4. # # http://volker.dnsalias.net/soft/nedit/ # # Place this file into $HOME/.nedit/ # and load it by adding the line # load_macro_file( "" ) # to $HOME/.nedit/autoload.nm # To activate the key bindings, file ....rc must also be loaded with ... # # Copyright (C) 2004 by Volker Kuhlmann , # Released under the same license as NEdit itself, # or, at your option, under the GNU General Public Licence, Version 2. # # ChangeLog: # 1.0, 16 Jan 2004 original version # 1.1, 07 Feb 2004 bugfix in bibtex_format_entry() # Key: Shift+Ctrl+N # Action: Scrolls the start of the next BibTeX entry to the top of the window. # define bibtex_scroll_next_entry { # Scroll next BibTeX entry to top of window end_of_line() find("@\\w+\\s*\\{", "forward", "regex", "nowrap") beginning_of_selection() scroll_to_line($line) beginning_of_line() } # Key: Shift+Ctrl+P # Action: Scrolls the start of the previous BibTeX entry to the top of the # window. # define bibtex_scroll_previous_entry { re="@\\w+\\s*\\{" beginning_of_line() # If cursor is inside an entry, scroll to the entry before, i.e. scroll # back twice unless cursor is on start of entry start = $cursor search("\n", $cursor) # only examine one line for efficiency if ( search_string(get_range(start, $search_end), re, 0, "regex") != 0 ) { find(re, "backward", "regex", "nowrap") } find(re, "backward", "regex", "nowrap") beginning_of_selection() scroll_to_line($line) beginning_of_line() } # Key: Shift-Ctrl-J # Action: Re-format BibTeX entry by running it through bibtool. Re-formats # the selection if there is one, the current entry otherwise. # bibtool is by Gerd Neugebauer, available from CTAN in # /tex-archive/biblio/bibtex/utils/bibtool/ # define bibtex_format_entry { bibtool="bibtool" if ($selection_start == -1) { # find start and end of current BibTeX entry pos = $cursor if ($column == 0) forward_character() backward_paragraph() start = $cursor forward_paragraph() end = $cursor - 1 if ($cursor == $text_length) end = $cursor # end of file, no NL if (end == start + 1) end = start set_cursor_pos(pos) # replace text with bibtool output newentry = shell_command(bibtool, get_range(start,end)) replace_range(start, end, newentry) # restore cursor position #end = start + length(newentry) #if (pos > end) pos = end #set_cursor_pos(pos) set_cursor_pos(min(pos, start + length(newentry))) } else { if ($selection_left == -1) { start = $selection_start newentry = shell_command(bibtool, get_selection()) replace_selection(newentry) end = start + length(newentry) select(start, end) set_cursor_pos(end) } else { dialog("Operation doesn't currently support rectangular\n" \ "selections. Would this even make sense?") } } }