Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref/cite completion: fixes and enhancements #120

Merged
merged 25 commits into from Jun 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d773fea
ref and cite autocomplete would crash if the current file is unnamed …
Westacular Dec 8, 2012
c548a0c
Correct bug that could result in "\\ref{" (note double slash) and mak…
Westacular Dec 8, 2012
bea6293
Automatically open the ref/cite completion list when typing { if the …
Westacular Dec 8, 2012
a33c728
Make command versions of cite/ref autocompleters also tolerant of the…
Westacular Dec 8, 2012
f0ef951
Refactor common code of the autocomplete plugin and the quick panel c…
Westacular Dec 8, 2012
a54f3d5
Rename error type, remove overzealous error response.
Westacular Dec 8, 2012
c544ab8
Refactor common autocomplete / quick panel command code into a shared…
Westacular Dec 8, 2012
059708a
Tweak ref_cite regexes to more accurately align with new and old form…
Westacular Dec 8, 2012
06f9958
Enable completion of multiple, comma-separated references in a single…
Westacular Dec 8, 2012
93d1a51
Correct some typos
Westacular Dec 9, 2012
3b996c2
Make ref and cite autocompletion slightly less eager (see: https://gi…
Westacular Dec 9, 2012
361d16a
Some more fixes to the ref/cite completion dispatcher regexes, to acc…
Westacular Dec 9, 2012
90cc976
Some fixing of the fix to make autocomplete less disruptive to normal…
Westacular Dec 10, 2012
882b064
Set the ref/cite dispatcher to just directly use the exact same regex…
Westacular Dec 10, 2012
b74abf3
Fix an error that prevented the { and , auto-opening of the cite/ref …
Westacular Dec 10, 2012
0ab3411
Add to ref completion recognition of/support for a variety of other r…
Westacular Dec 10, 2012
59d14c6
Add a setting -- "disable_latex_ref_cite_auto_trigger" -- that when s…
Westacular Dec 10, 2012
2cbeff4
Incorporating jlegewie's options for formatting of citation quick panel
Westacular Dec 10, 2012
ecb7262
Fix an error with ref completions.
Westacular Dec 10, 2012
18b8734
Tweak the { and , completion triggers, and add them to Linux and Wind…
Westacular Dec 10, 2012
7ef2e7d
Fix problems handling non-ASCII charsets (and disabled several print …
Westacular Dec 11, 2012
b38fc7c
Handle the { and , triggers in a more robust fashion, so that even if…
Westacular Dec 11, 2012
0e4726a
Add formatting options for the cite autocomplete entries (analogous t…
Westacular Dec 12, 2012
665cbd7
Set the ref and cite quick panel commands to leave the caret at the e…
Westacular Dec 13, 2012
404c0bf
Adds awareness of optional arguments to cite completion, allowing com…
Westacular Jan 8, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions Default (Linux).sublime-keymap
Expand Up @@ -41,6 +41,24 @@ LaTeX Package keymap for Linux
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"}],
"command": "latex_ref_cite"},

{ "keys": ["{"],
"context": [
{"key": "setting.disable_latex_ref_cite_auto_trigger", "operator": "not_equal", "operand": true},
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"},
{"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\\\\(((eq|page|v|V|auto|name|c|C|cpage)?ref)|(cite([a-zX*]*?)(\\[.*?\\]){0,2}))$", "match_all": true}],
"command": "latex_ref_cite", "args": {"insert_char": "{"}},

{ "keys": [","],
"context": [
{"key": "setting.disable_latex_ref_cite_auto_trigger", "operator": "not_equal", "operand": true},
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"},
{"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\\\\cite([a-zX*]*?)(\\[.*?\\]){0,2}\\{(?:[^{},]*,)*[^{},]+$", "match_all": true}],
"command": "latex_ref_cite", "args": {"insert_char": ","}},


// View PDF, jump to point, toggle editor/viewer focus and syncing behavior
{ "keys": ["ctrl+l","v"],
Expand Down
18 changes: 18 additions & 0 deletions Default (OSX).sublime-keymap
Expand Up @@ -41,6 +41,24 @@ LaTeX Package keymap for OS X
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"}],
"command": "latex_ref_cite"},

{ "keys": ["{"],
"context": [
{"key": "setting.disable_latex_ref_cite_auto_trigger", "operator": "not_equal", "operand": true},
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"},
{"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\\\\(((eq|page|v|V|auto|name|c|C|cpage)?ref)|(cite([a-zX*]*?)(\\[.*?\\]){0,2}))$", "match_all": true}],
"command": "latex_ref_cite", "args": {"insert_char": "{"}},

{ "keys": [","],
"context": [
{"key": "setting.disable_latex_ref_cite_auto_trigger", "operator": "not_equal", "operand": true},
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"},
{"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\\\\cite([a-zX*]*?)(\\[.*?\\]){0,2}\\{(?:[^{},]*,)*[^{},]+$", "match_all": true}],
"command": "latex_ref_cite", "args": {"insert_char": ","}},

// View PDF, jump to point, toggle editor/viewer focus
{ "keys": ["super+l","v"],
"context": [
Expand Down
18 changes: 18 additions & 0 deletions Default (Windows).sublime-keymap
Expand Up @@ -41,6 +41,24 @@ LaTeX Package keymap for Windows
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"}],
"command": "latex_ref_cite"},

{ "keys": ["{"],
"context": [
{"key": "setting.disable_latex_ref_cite_auto_trigger", "operator": "not_equal", "operand": true},
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"},
{"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\\\\(((eq|page|v|V|auto|name|c|C|cpage)?ref)|(cite([a-zX*]*?)(\\[.*?\\]){0,2}))$", "match_all": true}],
"command": "latex_ref_cite", "args": {"insert_char": "{"}},

{ "keys": [","],
"context": [
{"key": "setting.disable_latex_ref_cite_auto_trigger", "operator": "not_equal", "operand": true},
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"},
{"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true},
{"key": "preceding_text", "operator": "regex_contains",
"operand": "\\\\cite([a-zX*]*?)(\\[.*?\\]){0,2}\\{(?:[^{},]*,)*[^{},]+$", "match_all": true}],
"command": "latex_ref_cite", "args": {"insert_char": ","}},

// View PDF, jump to point, toggle editor/viewer focus
{ "keys": ["ctrl+l","v"],
"context": [
Expand Down
25 changes: 25 additions & 0 deletions LaTeXTools Preferences.sublime-settings
Expand Up @@ -9,6 +9,31 @@
// Sync PDF to current editor position after building (true) or not
"forward_sync": true,

// Formating of references in quick panel
/* This preference sets the format of the quick panel to select citations using wildcards.
The setting is a list with one or two string using wildcards for author, title, keyword etc.

Default setting: `["{title} ({keyword})","{author}"]`
Format:
Can quantum-mechanical description of physical reality be considered complete? This is an non-existing subtitle to illustrate (einstein1935quantum)
Albert Einstein and B Podolsky and N Rosen

Alternative: ["{author_short} {year} - {title_short} ({keyword})","{title}"]
Format:
Einstein et al. 1935 - Can quantum-mechanical description of physical reality be considered complete (einstein1935quantum)
Can quantum-mechanical description of physical reality be considered complete? This is an non-existing subtitle to illustrate

Alternative: ["{author_short} {year} ({keyword})"]
Format:
Einstein et al. 1935 (einstein1935quantum)

Valid wildcards: keyword, title, author, year, author_short, title_short
*/
"cite_panel_format": ["{author_short} {year} - {title_short} ({keyword})","{title}"],

// Similarly, the formatting for the autocomplete panel:
"cite_autocomplete_format": "{keyword}: {title}",

// Settings that are specific to Linux platforms
"linux": {
// Command to invoke Python 2. Useful if you have both Python 2 and Python 3 on your system,
Expand Down
32 changes: 26 additions & 6 deletions getTeXRoot.py
Expand Up @@ -2,7 +2,8 @@

# Parse magic comments to retrieve TEX root
# Stops searching for magic comments at first non-comment line of file
# Returns root file or current file
# Returns root file or current file or None (if there is no root file,
# and the current buffer is an unnamed unsaved file)

# Contributed by Sam Finn

Expand All @@ -17,9 +18,23 @@ def get_tex_root(view):


texFile = view.file_name()
for line in open(texFile, "rU").readlines():
root = texFile
if texFile is None:
# We are in an unnamed, unsaved file.
# Read from the buffer instead.
if view.substr(0) != '%':
return None
reg = view.find(r"^%[^\n]*(\n%[^\n]*)*", 0)
if not reg:
return None
line_regs = view.lines(reg)
lines = map(view.substr, line_regs)

else:
lines = open(texFile, "rU")

for line in lines:
if not line.startswith('%'):
root = texFile
break
else:
# We have a comment match; check for a TEX root match
Expand All @@ -30,9 +45,14 @@ def get_tex_root(view):
# Create TEX root file name
# If there is a TEX root path, use it
# If the path is not absolute and a src path exists, pre-pend it
(texPath, texName) = os.path.split(texFile)
(rootPath, rootName) = os.path.split(mroot.group(1))
root = os.path.join(texPath,rootPath,rootName)
root = mroot.group(1)
if not os.path.isabs(root) and texFile is not None:
(texPath, texName) = os.path.split(texFile)
root = os.path.join(texPath,root)
root = os.path.normpath(root)
break

if isinstance(lines, file):
lines.close()

return root