There’s a lot Emacs literature and config files floating on the internet. I’ll most likely have my own requirement/taste. I’ll focus on the tiny details that work for me. I’ll improve over my own copied-edited-hacked-together workflow.
Emacs startup can take a few seconds. If that’s unbearable for quick editing, then have an emacs server running.
$ emacs --daemon
Whenever required, use
emacsclient to connect to it.
emacsclient expects a file name argument to open.
$ emacsclient foo.txt
If I don’t have a file to open, then I use the
$ emacsclient -nw
I usually alias the above to
alias em="emacsclient -nw"
To kill the Emacs server I can run
M-x kill-emacs from an emacsclient. The Emacs wiki suggests the following:
$ emacsclient -e '(kill-emacs)'
I will alias this to whatever I see fit. But I’ve found shutting down emacs is something I’ve rarely done though. So I’ll just leave it for later.
There were times when I didn’t have an emacs server running. If I had to quickly get back to the shell, I would press
ctrl-z to background emacs. And then bring it back with the
fg shell command.
Helm’s introduction on github says this:
Helm is incremental completion and selection narrowing framework for Emacs
AFAIK I have helm in my emacs config for a couple years now. I haven’t yet figured out what that means. But it’s useful because it gave me the fuzzy search I found handy in vim (ctrl+p), SublimeText & Atom.
(global-set-key (kbd "C-x f") 'helm-find)
C-x f would invoke helm’s fuzzy file search, which is awesome.
projectile is a project management package for Emacs.
helm-projectile provides helm bindings for projectile. I found very good use for it a few hours before this writing.
I sometimes have 3 repositories I switch between frequently. Projectile makes that seamless.
;; turns on projectile mode by default for all file types (projectile-global-mode) ;; asks for file to open when project is switched (setq projectile-switch-project-action 'helm-projectile-find-file) ;; turns on helm bindings for projectile (helm-projectile-on)
Here’s a workflow:
serverrepository, I run
M-x helm-projectile-switch-projectand choose the file
This works because projectile recognizes
.git directories to identify a project’s root folder.
helm-projectile also allows grepping the project with
M-x helm-projectile-grep. Grepping is something that I haven’t yet configured properly. It doesn’t seem to respect gitignore irrespective of my config to do so. Saving it for the future.
;; ask projectile to use git grep ;; so that files in gitignore wont be grepped (setq projectile-use-git-grep 1)
It’s going to be daunting to invoke those helm-projectile commands frequently with
M-x. I know I’ll come across such commands everywhere.
M-x describe-function shows keystroke bound for a function (along with more details). I’m going to be meta and find the key shortcut for
M-x describe-function. I can run the command and enter
describe-function as the function name.
C-h f is bound to
C-h f is my swiss knife.
I use my new-found knowledge of
C-h f and find out the following shortcuts.
pp is projectile project.
pf is projectile find.
psg is the name of the college a friend studied at.
All this while I’ve been typing this blog post in a file, in an unrelated project directory. Wasn’t confident if this will actually turn into a post or few-minutes rambling that I will
rm soon after.
So now I attempt to copy this by starting to mark the entire buffer line by line.
mark the entire buffer. Oh. mark- something maybe?
C-h f, then
mark-whole-buffer in the suggestions.
C-x h to select the entire thing and off I go.