Skip to content

Instantly share code, notes, and snippets.

@Bad-ptr
Last active September 11, 2015 12:06
Show Gist options
  • Save Bad-ptr/e05fb8d02436214abd89 to your computer and use it in GitHub Desktop.
Save Bad-ptr/e05fb8d02436214abd89 to your computer and use it in GitHub Desktop.
Open files in single emacs instance without daemon.
#!/bin/bash
if pidof emacs &> /dev/null; then
echo "$1" >> /tmp/emacs-files-to-find
else
emacs "$1"
fi
(defvar files-to-find-file-name "/tmp/emacs-files-to-find")
(defvar files-to-find-buffer (or (find-buffer-visiting files-to-find-file-name)
(with-current-buffer (find-file-noselect files-to-find-file-name)
(rename-buffer " *emacs-files-to-find-buf*")
(save-buffer)
(current-buffer))))
(defun files-to-find-func-for-hook ()
(let ((files (split-string
(with-current-buffer files-to-find-buffer
(let ((ret (buffer-string)))
(erase-buffer)
(save-buffer)
ret))
"\n" t "[ \t\n]")))
(mapc #'find-file files)))
(with-current-buffer files-to-find-buffer
(add-hook 'after-revert-hook #'files-to-find-func-for-hook nil t)
(auto-revert-mode))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment