Showing posts with label emacs-tidbits. Show all posts
Showing posts with label emacs-tidbits. Show all posts

2008-11-19

Emacs Tidbit #3

For those of you who have blogs hosted on blogger (like this one), and use emacs, I'm sure you've run into this - writing a post in emacs with auto-fill mode on leads to an ungodly amount of reformatting needed because of the insertion of hard line breaks.

If you weren't already aware of it,

longlines-mode
solves this problem.


longlines-mode is an interactive compiled Lisp function in `longlines.el'.
(longlines-mode &optional arg)

Toggle Long Lines mode.
In Long Lines mode, long lines are wrapped if they extend beyond
`fill-column'. The soft newlines used for line wrapping will not
show up when the text is yanked or saved to disk.

If the variable `longlines-auto-wrap' is non-nil, lines are automatically
wrapped whenever the buffer is changed. You can always call
`fill-paragraph' to fill individual paragraphs.

If the variable `longlines-show-hard-newlines' is non-nil, hard newlines
are indicated with a symbol.

This, in combination with the ability to post stuff to blogger through email, makes using emacs with your blogger account a bit easier.

One more thing - never, ever, while in the blogger "new post" editor, hit Ctrl-P, unless you really want to publish. It can be awfully frustrating.

2008-11-11

Emacs Tidbit #2

Ever make a throwaway buffer in some random directory that you didn't intend on saving, but then ended up wanting to save - but not in that directory?
M-x set-visited-file-name

Is what you want.

From the docs:

set-visited-file-name is an interactive compiled Lisp function in `files.el'.
(set-visited-file-name filename &optional no-query along-with-file)

Change name of file visited in current buffer to filename.
This also renames the buffer to correspond to the new file.
The next time the buffer is saved it will go in the newly specified file.
filename nil or an empty string means mark buffer as not visiting any file.
Remember to delete the initial contents of the minibuffer
if you wish to pass an empty string as the argument.

The optional second argument no-query, if non-nil, inhibits asking for
confirmation in the case where another buffer is already visiting filename.

The optional third argument along-with-file, if non-nil, means that
the old visited file has been renamed to the new name filename.


This just saved me a few commands, hope you find it useful, fellow emacs-learners. Don't forget to follow the link to files.el and read the code for the function.

2008-09-26

Emacs tidbit

I've been using emacs regularly for around one year now, and I am always running into reminders that I need to consistently learn more about what's available to you in emacs. It's frankly a bit hard to schedule getting stuff done in emacs with learning more about what's available through (or in) emacs, but the return value for learning a bit more about what you can do is very high - there are things that can make you magnitudes more productive just sitting around waiting to be found.

A small tidbit, from earlier today: kmacro-insert-counter inserts the number of times a macro has been called into the buffer.

I was debugging some methods, and had a bunch of similar calls that I wanted to log info about to files named in a sequential order (foo1.txt, foo2.txt). I just needed to do a diff of the output. I made a little macro that used kmacro-insert-counter. Wasn't the most robust debugging solution, but then again I wasn't in need of one at the time, just needed to see some data as quickly as possible.

There have been a few other times where I've wanted something like kmacro-insert-counter. It's not something that's useful (to me) on a very regular basis, but when it's handy, it's really handy. Emacs is chock-full of stuff like that, and if you're familiar with what's there, combining all the little convieniences into one big project-or-file-specific convienience is easy, and allows you to do non-trivial editing tasks much faster than I've been able to accomplish with other editors.