Code Monkey home page Code Monkey logo

macvim-skim's Introduction

macvim-skim

Tools for integrating macvim with Skim.app. Adds shortcuts to vim so that you can go to the current line in the PDF from a tex document. Adds a tool to Skim so that shift-command-clicking on a line brings you to that line in the source code.

Example: Screenshot example of intended environment

Shortcuts:

  • <leader>v - view current .tex file in Skim at current line
  • <leader>p - rebuild current .tex file with pdflatex -synctex=1, then active Skim at current line
  • <leader>m - Run the command make in the current directory, then activate Skim at current line
  • <leader>r - activate Skim at current line, then bring vim back to the front
  • <leader>t - <leader>p + <leader>r: rebuild current file, then bring vim back to the front

From Skim:

  • Shift-Command-click on a line to go to that line in the .tex file

INSTALLATION

Easiest way: run macvim-skim-install.sh. By default, installs a shell script to your $HOME/bin/ directory, installs Skim.app version 1.4.1 if Skim is not already installed, and puts WhichTab.vim in your plugins directory. It will also add the shortcut lines to your $HOME/.vimrc.

INSTALLATION OPTIONS

Variables used in installation process:

  • PREFIX (default $HOME/bin)
  • VIMDIR (default $HOME/.vim/)
  • SKIMPATH (default /Applications/Skim.app)

If you want to specify a different install directory for the executable file, specify the PREFIX variable, e.g.: PREFIX=/usr/local ./macvim-skim-install.sh

You can also specify the path to Skim.app with the variable SKIMPATH. If you do not use the default /Applications/Skim.app, you'll need to set the vim variable g:macvim_skim_app_path in your ~/.vimrc (this step has been removed from the automatic installation, as I don't think install scripts should modify your .vimrc)

Manual Install

If you want to install manually, Copy macvim-skim to ~/.vim/plugins/. Put macvim-load-line on your path.

Aside

Was hosted at http://code.google.com/p/agpy/source/browse/trunk#trunk%2Fmacvim-skim until 1/20/2013. No issues were posted on agpy, though.

macvim-skim's People

Contributors

aakashjog avatar keflavich avatar tbelaire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

macvim-skim's Issues

Need to select correct window after selecting tab in mvim

I was working on my "SmartOpen" script, and thought of an issue that I came back to check on in your bash script...

# you find the correct instance of mvim if several are running, 
# and find one that contains a loaded buffer of the file you're 
# looking for ($foundfile)
mvim --servername $server --remote-expr "foreground()"
mvim --servername $server --remote-send ":exec \"tabnext $foundfile\" <CR>"
mvim --servername $server --remote-send ":$line <CR>"

OK, so you select the correct tab, then jump to the desired line. The problem is that tabs can have multiple split windows inside them, and this technique is just going to give focus to whichever window was last used on that tab by mvim when it switches to it with :tabnext.

To reproduce:

  1. open the doc in Skim.app
  2. open the source in mvim
  3. in that same tab in mvim, create another window with :new whatever
  4. make another tab in mvim (not necessary, but helps to demonstrate)
  5. go back and invoke your bash script from within Skim.app (shift-command-click?)

This should switch to the correct tab, but not the correct window within that tab, and your --remote-send ":$line <CR>" will either jump to the line in the other window's buffer or its last line if $line exceeds its number of lines.

So, you could write another function and instead of making 3 calls to mvim from the shell, just make one call that executes the foreground, tabnext, SelectWindow of some sort, and then :$line. However, I was also thinking.. you probably need to break that loop after you succeed in finding an mvim server with your source file open. If you have multiple mvim servers (gui windows) running, you probably don't want this script playing a game of musical windows on your desktop. ;)

I wrote a vim function that has been working great the past few days of use, although I can't say it's 100% bulletproof. Instead of trying to find the right tab and window, it takes advantage of vim's behavior in the command :sbuffer:

:[N]sb[uffer] [N]                   *:sb* *:sbuffer*
    Split window and edit buffer [N] from the buffer list.  If [N]
    is not given, the current buffer is edited.  Respects the
    "useopen" setting of 'switchbuf' when splitting.  This will
    also edit a buffer that is not in the buffer list, without
    setting the 'buflisted' flag.

So, what I do is capture the user's current settings for &switchbuf, save them, set it to the necessary setting of let &switchbuf = "useopen,usetab", then check if the buffer's loaded somewhere and call exec "sbuffer" bufNo. Vim then switches to the correct tab & window automagically without me having to muck with searching through tabs and windows myself. Then I set the user's original settings back to &switchbuf. Anyway, I modified what I had for you:

function! MVS_Focus(filename, line)
  " See if the given filename is found to be loaded in any tab/window
  " if so, raise window, switch to file's tab, window, and jump line
  let oldSwitchBufOpt = &switchbuf
  let &switchbuf = "useopen,usetab"
  let bufNo = bufnr('\(^\|/\)' . a:filename . '$')
  if (!bufNo || !bufloaded(bufNo))
    return 0
  endif
  call foreground()
  exec "sbuffer" bufNo
  let &switchbuf = oldSwitchBufOpt " restore user's switchbuf option
  exe ":silent! :".a:line
  " see if you like this... could also pass a number of lines down to highlight
  exe ":normal V"
  call REcho(printf("Focused on %s line %d by macvim-skim.", fnamemodify(bufname("%"), ":f"), a:line))
  return 1
endfunction

" Redraw-echo (:he echo-redraw) -- more reliable echo!
function! REcho(msg)
  redraw | echo a:msg
endfunction

Now you can just make a single call to each mvim server...

for server in mvim --serverlist
do
if [[ $debug ]] ; then echo mvim --servername $server --remote-expr "MVS_Focus('$file', '$line')"; fi
finished=mvim --servername $server --remote-expr "MVS_Focus('$file', '$line')"
if [[ $finished > 0 ]]
then
echo Succeeded on servername: $server
break
fi
done

Install latest skim instead of fixed version

Right now I hard-link to a particular version of Skim.app on sourceforge. It would be better to use the latest version, but I'm not sure how to do that with sourceforge links.

Deal with filenames that might be subsets of other open filenames

According to :help bufname()

bufname({expr}) *bufname()* The result is the name of a buffer, as it is displayed by the ":ls" command. If {expr} is a Number, that buffer number's name is given. Number zero is the alternate buffer for the current window. If {expr} is a String, it is used as a |file-pattern| to match with the buffer names. This is always done like 'magic' is set and 'cpoptions' is empty. When there is more than one match an empty string is returned.

Since the string is used as a pattern, it might match part of another buffer name. The 'magic'-like behavior will save you in a lot of common cases, but there are still some gotchas. To avoid them, instead of calling:
let buffername = bufname(a:filename)
You can call:
let buffername = bufname("^" . a:filename . "$")

i.e., a regex that says the entire buffer must match the filename.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.