Pages

Monday 12 October 2015

Some emacs tips



I've finally bit the bullet and decided it's time to learn Emacs.
In the past, I've avoided learning this behemoth because of it's steep learning curve. Only thing, it's not that hard.

I should've attempted to learn it ages ago, but better late never. After using Emacs for a while, I'm starting to learn how powerful it is but still in the infancy of the learning curve and looking forward to becomming better at using it. One thing I've noticed is that it's far more capable than any text editor I've ever used, it's more like a complete OS.

So, on to some quick customizations..




Choosing a theme

I prefer a dark theme that is easy on the eyes and saves eyestrain. To do this, go to Options > Customize Emacs > Custom Themes and I use the "Deeper Blue" theme.

Be sure to click the "Save theme settings" so the changes are persistant.





Adding a repository

One of the first things I do is add the Melpa repositories to give it far more plug-ins. To do this, open Emacs and then your emacs config file:

ctrl x, ctrl f then open your ~/.emacs file.

We then need to copy the repository from Melpa into your .emacs config file.

To save the file, use ctrl x, crtl s

Then we restart Emacs for the changes to take effect.




Removing the toolbar

I'm not a fan of toolbars, I'd rather use shortcuts of get to the command via the menu, so I remove that. Here's how.

Go to Options > Show/Hide > Toolbar and select "None"

You can hide and un-hide other elements to your liking here also.

Buffer switching

Switching buffers in Emacs is a hassle to start off with, I'm still getting my head around different methods. But in the mean time, I've found a shortcut that emulates the way we do it in the normal world. You can use plain old ctrl tab to cycle forwards and ctrl shift tab to cycle backwards.
Simply add these two lines to your  ~/.emacs config

(global-set-key (kbd "C-<tab>") 'next-buffer)
(global-set-key (kbd "C-S-<tab>") 'previous-buffer)

I've found that it helps the transition to Emacs a bit easier than typing the buffers out in ctrl x, ctrl b


Line numbers

Displaying line numbers is, to me; essential in programming, to quickly find errors and focus where you need to look. For some reason, Emacs doesn't display this out of the box so heres how to get it going.


Open your ~/.emacs config file and add the following line to the bottom:

(global-linum-mode t)

(Dont forget that paste in Emacs is ctrl y)

And now we have line numbers along the left of the screen, brilliant.




Changing the default font and size

I find it hard to see at times and I'm always increasing the size of the fonts, maybe it's time for glasses.

So if you also need to adjust the default font and font size in Emacs, heres how...

Open M-x (the meta key is usually your alt key) and type customize

That will bring you to the custimization settings, grab yourself a beverage because there are loads of settings to be toggled off and on.

Whenever you do change something, always remember to click "State" and if you want it to be remembered, then
click "Save for future sessions"

Emacs measures font size in points, so play around till you find whatever suits you best.

I use Deja Vu Sans 135, works for me.
Another way to increase/decrease font size is ctrl x ctrl +/ctrl x, ctrl -



Other things
If you get confused withe the key bindings and Emacs groans at you, cancel the current command with ctrl g.


You can find an abundance of further tweaks by the shortcut meta x, customize.
I haven't got my head around all the options yet and I'm sure it'll take a long time to understand it fully.


No comments:

Post a Comment