Emacs Weekly Tip #4: Super Quick Navigation with Registers

Posted: May 9th, 2011 | Author: Rob Searles | Filed under: Emacs | Tags: , | Comments

If like me you are constantly bouncing about between different places within a file, or even between multiple buffers then you should save a lot of time by using Registers.

Registers are a handy little tool that enable you to save a snippet of information for the length of your session. This snippet of information can be either text, numbers, rectangles and even window configurations.

For the benefit of this tip, however, we’ll be saving a position within the register. It is so simple, it is actually quite silly.

When you are at a position you want to save, simply enter:

C-x r <space> q

This will save your current location into the register “q”. You can replace “q” with any single character. For some reason I always use “q”, “w”, “e”, “r” etc. but you can use whatever you want.

To remember this command, you simply need to think about saving a space in a register called q.

Jumping back to the position saved in the register is just as simple

C-x r j q

You are jumping to register q

Once you have the hang of it, it’s pretty effortless.

Soon you’ll be jumping about like a maniac!


Emacs Weekly Tip #3: Learn Org-Mode

Posted: April 18th, 2011 | Author: Rob Searles | Filed under: Emacs | Tags: , | Comments

As my aversion to all things rodent orientated increases and my use of Emacs grows so too does my use of org-mode.

Org-Mode probably doesn’t need any introduction. It can be used for pretty much any sort of organising you require, from sketching out blog posts (this article was drafted in Org-Mode before being published to Wordpress) to a full productivity and GTD suite.

The Emacs tip this week isn’t about highlighting all the useful features Org-Mode has to offer, but instead it is more of a “How-to-Learn” rather than a “How-To”.

Read the rest of this entry »


Emacs Weekly Tip #2: Recent Files with recentf

Posted: April 11th, 2011 | Author: Rob Searles | Filed under: Emacs | Tags: , | Comments

In my daily Emacs activities I open a lot of files. However, during the week I am normally opening the same files as I’m generally working on the same stuff. Emacs’s Recent Files (recentf) feature generates a list of my recently used files and allows me to display that list so I can quickly open any of them.

To enable recentf mode, add the following into your Emacs init file (which you are version controlling right?)

;; recentf stuff
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)

If you use Tramp a lot you may want to disable the auto-cleanup command for Recentf. This is simply because every now an then, if enabled, the auto-cleanup feature scans a list of your recent files, and tries to stat them to see if they should remain in the list. Obviously, if it tries to stat any remote files this may cause your system to temporarily hang.

;; recentf stuff
(require 'recentf)
(setq recentf-auto-cleanup 'never) ;; disable before we start recentf!
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)

Now use Emacs for a bit to generate a list of your recently used files. Next time you open Emacs, simply hit C-x C-r and you’ll be greeted with a list of your recently used files.

A great time saver.

For more info, visit the Emacs Wiki page.


Emacs Weekly Tip #1: Version Control Emacs.d

Posted: April 4th, 2011 | Author: Rob Searles | Filed under: Emacs | Tags: , | Comments

Welcome to the first of my weekly Emacs top tips.

This first tip is something that I’m seeing more and more people do, especially with the excellent Emacs Starter Kit aiming to get Emacs newbies up and running quickly:
Version control your emacs.d directory.

This technique is especially useful if you have a number of development machines that you work from (desktop, laptop, remote server).  This is the reason why I started to version control my .emacs.d directory. Whilst my configuration is still very basic (for now) I find it invaluable.

Whilst it is useful to version control your configuration file, a happy side effect of the increasing prevalence of services like GitHub is that you can see other Emacs users’ setups. It is great to look at these, borrow some ideas and lean some new techniques. After some Googling, I’ve quickly compiled the  list below from GitHub, which is by no means exhaustive:

So what are you waiting for? Put your Emacs config directory into Git, share it on GitHub and post the respoitory URL in the comments below.


Introducing Emacs Weekly Tips

Posted: April 1st, 2011 | Author: Rob Searles | Filed under: Emacs | Tags: , | Comments

As regular readers of my poor, infrequently updated blog may know my editor of choice is the wondrously magnificent Emacs.  One of the reasons I like Emacs is because there is so much more to learn. I can easily imagine that one could spend every day for a whole year learning a new technique, mode or snippet within Emacs and still not come close to learning all there is to know about it.

Sadly, I’m not dedicated enough to learn a new tip every day.

However,  I am going to try and learn one a week. My aim is to pick up a new Emacs top tip, use it for a week and post about it here on my blog. This should hopefully increase my knowledge of Emacs and server as a repository of this information.

So, tune in every Monday for my Emacs Tip of the Week!

For those that can’t wait, there are loads of great places for all things Emacs out there. Check out:


Three Useful Emacs Blogs

Posted: November 11th, 2010 | Author: Rob Searles | Filed under: Emacs | Tags: | Comments

The past few months I have spent most of my time head down, working on a number of projects. In work, I spend most my time in Emacs, which has been my editor of choice for just over a year. Over the past year, my knowledge of Emacs, and my associated productivity is improving all the time. However, the Emacs universe is so vast there is no possible way to know everything, or every little command (or even every “big” command).

My tactic recently has been to try and learn one new useful tip each day, whether it is switching to ibuffer instead of the normal buffer mode, or trying to use M-^ (delete-indentation) more. Whilst trawling through the Emacs Wiki or a list of command references may be a good way to find some useful stuff, a better way is to let someone else do all the hard work for you!

So here are three blogs that I have found great for general Emacs related tips and tricks:

  • Emacs Fu – Simply put, a fantastic resource.
  • Mastering Emacs – A brand new blog, looks promising.
  • M-x All Things Emacs – Hasn’t been posted to since July 2009, but still has lots of good tips in the archives.

Enjoy.


Easily Add Current File to SVN Within Emacs

Posted: May 14th, 2010 | Author: Rob Searles | Filed under: Emacs, Tutorials | Tags: | Comments

As I’ve now been using Emacs for quite a long time, I have picked up a few tips along the way. One thing I’ve been doing more and more is using the shell within Emacs. (For more details see here and here.)

Some of my most used shell commands are using SVN, such as add, revert etc. However, I couldn’t find anywhere to just add/revert the current file I am working on. Fortunately there is Stack Overflow! Someone with a very similar issue to me has had a couple of good answers, which I have “borrowed” and now adding files to my SVN repository is really easy.

First, add the following to your .emacs file

(define-key minibuffer-local-map [f3]
(lambda() (interactive) (insert (buffer-file-name (nth 1 (buffer-list))))))

Now either open up Emacs, or reload your .emacs file:

M-x load-file RET ~/.emacs RET

Now, when you are working on a new file you can easily add it to SVN with the following command:

M-! svn add F3 RET

Nice!


Converting from Mac to Unix line endings

Posted: March 10th, 2010 | Author: Rob Searles | Filed under: Linux, Tutorials | Tags: | Comments

This is more a post for me than anyone else, but I thought I’d share anyway.

In our team we have a mixture of Linux and Mac users, and we are constantly editing the same files. One of the most irritating things is when a file is saved with Mac line endings instead of Unix line endings (displaying as ^M in Emacs). This happens very rarely, but on the occasion it does I can quickly convert back using the following commands on my Linux box:

$ tr '\r' '\n' < file-in-question.txt > tmp.file
$ mv tmp.file file-in-question.txt

Works perfectly

If you want to find more about the tr (Translate) program, visit the man page.


Emacs CSS-Mode Fix (adding to the chain!)

Posted: October 29th, 2009 | Author: Rob Searles | Filed under: Open Source, Tutorials | Tags: | Comments

After my week with Emacs I’m still struggling along. One of my main annoyances is the default way some of the modes indent the code. I think the worst offender of this is the default CSS-mode. After frustration when, yet again, I hit the tab key and the cursor rockets about 80 places to the right I decided to Google for a fix.

The internet is great! Clearly it wasn’t just me having a problem, Guido Stevens was also suffering and posted a fix, which he himself found on another blog post by Chris Miller, which Chris in turn found on StokeBloke.com which had been found originally on a now dead post.

Not bad! Four people all having problems with the same thing and posting a fix for others to share. So I thought I’d join the chain, and write this blog post.

Oh yes, and the fix itself:

;; fix css mode
(require 'css-mode)
(setq cssm-indent-level 2)
(setq cssm-newline-before-closing-bracket t)
(setq cssm-indent-function #'cssm-c-style-indenter)
(setq cssm-mirror-mode t)

A week with Emacs: one week later

Posted: October 25th, 2009 | Author: Rob Searles | Filed under: General, Open Source | Tags: | Comments

As promised in my last post, I have spent a whole week using Emacs.   Apart from the odd foray with Nano and Mousepad I  haven’t touched Eclipse or Netbeans or any other IDE and  managed to stick to Emacs for the full week.

How did it go?

To start off it was slow. Emacs has a notoriously high learning curve, and I pretty much started at the bottom. One of the reasons for doing this was so I could move away from the mouse and it turns out that the mouse is an extremely hard habit to break. So to are the keyboard arrow keys. I kept on finding my hands would instinctively  jump off the keyboard and try to double click on something, or try to navigate around the page with the arrows. This is clearly not the way it is done in Emacs!

The next thing I found is that Emacs doesn’t let you indent code files as you want. It seems to have a preferred method and forces it on you. This is very annoying and being a n00b I still haven’t found a way around this.

However, after a couple of days I began to get the hang of it. Still painfully slow, but navigating around the page, buffers and windows was becoming gradually quicker. I began to enjoy using Emacs, even though my right hand kept on unceremoniously lurching to the right from time to time.

By a complete coincidence, on Wednesday I was invited to C-Base here in Berlin for a beginners’ introduction to Emacs. Even though it was all in German, and my Deutsch ist nicht so gut I was blown away by not only the speed but also the huge amount of functionality within Emacs. To see someone who actually knew Emacs inside out was a revelation. I made a huge amount of notes (within Emacs before you ask!) ready to test out for myself. This insight into the “how the pros use Emacs” has really been an eye-opener and I am determined to learn just a fraction of what was on display at the tutorial.

Summing up my week with Emacs.

It was hard work, there was much and is even more left to learn. It is a vast landscape to negotiate, with many nooks and crannies. But once it is mastered I have no doubt that my productivity will be greatly increased.

Other people diving into Emacs

Some useful sites