Skip to content

Instantly share code, notes, and snippets.

@til
Created July 14, 2012 11:43
Show Gist options
  • Save til/3110785 to your computer and use it in GitHub Desktop.
Save til/3110785 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Calls a running emacs server to visit a file, and optionally move
# point to a line number when included after a colon, e.g. like the
# one from a ruby stacktrace:
#
# emacs-find-file foo/bar.rb:123
abort "Usage: emacs-find-file <file>" unless ARGV[0]
file, line_number = ARGV[0].split(':')
find_file = "(find-file \"#{file}\")"
lisp = if line_number
"(with-current-buffer #{find_file} (goto-char (point-min)) (forward-line (1- #{line_number.to_i})))"
else
find_file
end
`emacsclient --no-wait --eval '#{lisp}' > /dev/null`
@til
Copy link
Author

til commented Jul 14, 2012

Got a special place in my bash: alias e='emacs-find-file'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment