Posts tagged ‘emacs’

Getting emacs to behave more like vim

Although the viper mode does not provide a lot of vim’s motions e.g diw and similar. The vimpulse plugin (http://www.emacswiki.org/emacs/download/vimpulse.el) does extends viper to provide several of these.

Supported commands in include

diw, ciw, yiw, di”, da”, ci”, ca”, yi”, ya”,
di(, da(, ci(, ca(, yi(, ya(,
di’, da’, ci’, ca’, yi’, ya’,

(take that google)

I find these vim text objects fairly useful.

November 22, 2009 at 6:13 pm Leave a comment

Making viper mode in emacs use C-[ for escape rather than escape

Pressing the actual escape button is far too much effort, so my brain seems to have decided to learn to us C-[ in vim in preference to escape.

To get this working in viper add the following line:

(setq viper-ESC-key “\C-[“)

To your emacs init file before you have required viper. Note that this variable cannot be set in your .viper file or changed after you have loaded viper, or rather it can but it has no effect.

November 18, 2009 at 2:59 pm 1 comment

viper-want-ctl-h broken when set in .viper

This happens in the emacs viper vim emulation mode shipped with ubuntu 9.10 in November 2009.

There is a work around by setting viper-want-ctl-help-h in your emacs init file after viper has been imported.

This bug occurs because viper-set-expert-level which is called as part of loading viper tramples on various viper settings. However it does need to set those settings which have not been overwritten in your .viper file.

As a workaround in viper one could do one of the following:

i) Make viper-set-expert-level only set those settings which are not already set if dont-change… is set to true
ii) Load the .viper file twice once after calling set-expert-level (hackish but it works)
iii) Do something crazy so as to have shadowed variables, where the set-expert-level only sets the value that is shadowed.

However, I am not going to change any of this at the moment.

November 18, 2009 at 1:15 pm Leave a comment

Using flymake in emacs to validate xml as you type

Motivation

  • Seeing mistakes earlier can make them easier to correct
  • Many programs will simply die with little logging if given broken xml files
  • Remembering to run a validator takes effort

Setup

  • Install rxp (this is available under cygwin on windows, and using apt under most linuxes)
  • Create this perl scripts, make it executable and place it on your path [1] call it xmlparse
    #!/usr/bin/perl
    open(HA, "rxp $ARGV[0] 2>&1|");
    while (){
        /^Error/ && chomp;
        print;
    }
  • Add the following code to your .emacs file
  • (defun flymake-xml-init ()
      (let* ((temp-file (flymake-init-create-temp-buffer-copy
    		     'flymake-create-temp-inplace))
    	 (local-file (file-relative-name
    		      temp-file
    		      (file-name-directory buffer-file-name))))
        (list "xmlparse" (list local-file))))
    
    (add-to-list 'flymake-allowed-file-name-masks
    	     '("\\.xml\\'" flymake-xml-init)) 
    
    (add-to-list 'flymake-err-line-patterns
    	     '("\\(.*\\) at line \\([0-9]+\\) char \\([0-9]+\\) of file://\\(.*\\)"
    	      4 2 3 1))
  • Also, ensure that you have the following command somewhere in your .emacs file
     (add-hook 'find-file-hook 'flymake-find-file-hook)

This should then work. You might like to change the face used to show errors with M-x customize-face flymake-errline. Hovering over an error will show you a description of the error

Caveats

The behavior for unclosed tags is not what I want. The error is reported where the parent tag closes – which can be quite some distance from the opening tag. However at least the message is informative.

There is an existing emacs host, nxhtml, which has some of these things built in together with other editing tools – but it looks a little monolithic.

[1] This ensures that each error is written on only one line. Flymake appears to only be able deal with output in this form.

February 23, 2009 at 11:44 pm Leave a comment

Emacs version control

I discovered how emacs version control worked today… and was duelly impressed. (Having previously thought that it didn’t work at all well – guess this means I should learn to read manuals).[1]

Regardless, emacs comes with a unified version control front-end which supports back-ends for most version control systems : I believe this includes git, svn and bzr).  This can do most of the things that one wants to do.

One of my only irritations is that one can’t revert individual lines of the diffs that it shows.

Summary for the impatient

Emacs version control is wonderful, I’m dim for not realising this earlier. To make it work do the following:

C-x v = in a file for a diff

To submit:

C-x v d <TOP LEVEL DIR> to get a list of all modifed files, then mark everything (hold down m) and press C-x v v.

If you want to see diffs for individual files press v=.

[1] As an aside, one of the reasons I hadn’t found this out earlier was because I was under the false impression the mode help (C-h m) would show all relevant keybindings… I’m not quite sure why, C-h b is (strangely!) better for this purpose.

July 30, 2008 at 10:33 pm 3 comments

Searching multiple buffers emacs

FSF has two magic functions for searching multiple buffers:

multi-occur: – Search specified buffers to a string

multi-occur-in-matching-buffers: Allows one to search a subset of one’s open buffers or files specified as a regexp:

Given .* as its first argument, this allows one to search all currently open files for a given regular expression.

Given a prefix argument and .* as its first argument, this allows one to search all currently open buffers for a regular expression.

Also (occur-1 regexp nil buffer-list) can be usefully adapted to search for other things.

July 27, 2008 at 6:43 pm 5 comments

Emacs buttons – an introduction for the somewhat impatient

Working out how to make buttons work in emacs took rather too much effort – I suspect I was just being slow. However, I thought I’d write a tiny how-to for anyone else who tries to do this:


Below is a prototypical emacs lisp function call to create a new button in your text between characters beg and end is:

(defun f (button)
    (call-interactively 'find-file))

(make-button beg end 'action 'f 'follow-link t)

Note the following:

  • The properties are defined via a variable number of arguments . It does does not take a list.
  • Removing the follow-link property would cause left mouse-clicks on the link to have no effects
  • f must take a single argument otherwise this will fail.

For more on emacs buttons see:

http://www.gnu.org/software/emacs/manual/html_mono/elisp.html#Buttons

If you want to make your button more anonymous (so that changing the function value associated with f has no deleterious results) you can use the following

(make-button beg end 'action
    (lambda (button) (call-interactively 'find-file))
    'follow-link t)

May 14, 2008 at 7:08 pm 3 comments

Sending mail through gmail Using Emacs

Very brief summary for the impatient
Ensure that the gnutls-bin program is installed (

apt-get install gnutls-bin

on ubuntu)

Paste the following into your init file changing username and password as appropriate.

(setq send-mail-function 'smtpmail-send-it)
(setq smtpmail-smtp-server "smtp.gmail.com")
(setq smtpmail-smtp-service 25)
(setq smtpmail-auth-credentials '(("smtp.gmail.com" 25 "USERNAME" "PASSWORD")))
(setq smtpmail-starttls-credentials '(("smtp.gmail.com" 25 nil nil)))

Evaluate this with “M-x eval-buffer”

Done

Longer explanation for the troubled / interested

Emacs can, if set up correctly, send mail through gmails smtp server.

First tell emacs to use smtp to send mail by evaluating:
(setq send-mail-function ‘smtpmail-send-it)

(If you don’t do this email will attempt to use sendmail to send mail – on my machine this resulted in mails not being sent despite emacs reporting that they were).

You must then set smtpmail’s authentification details. First run

(setq smtpmail-debug-info t)
(setq smtpmail-debug-verb t)

so as to get as much output as possible.

Then run

 
(setq smtpmail-smtp-server "smtp.gmail.com")
(setq smtpmail-smtp-service 25)

to tell emacs to use gmail for outgoing mail.

There are (at least) two mechanisms that smtp servers can use to authenticate users.

One method has the user provide a user name and password in plain(ish) text in the smtp connection. This connection can also be encrypted. This encryption mechanism is known as STARTTLS. Gmail uses a plain text authentication method sent over an encrypted connection in this manner.

With the other method, the user passes a certificate to the server which asserts that the user is who they say they are. This method of authentication is, confusingly, also know as STARTTLS.

To set-up authentication within SMTP evaluate

(setq smtpmail-auth-credentials '(("smtp.gmail.com" 25 "USERNAME" "PASSWORD")))

To set up STARTTLS encryption of the connection call

(setq smtpmail-starttls-credentials '(("smtp.gmail.com" 25 nil nil)))

(This variable is also used to set up authentication using STARTTLS).

After you have done this you should be able to send mail from within emacs. To test this run hit
C-x C-m. Write a test message, and then hit C-c C-s, before toggling to a buffer with a name beginning with “*trace of SMTP.” If anything goes wrong this should tell you the approximate reason.

More details

There doesn’t seem to be a way to make emacs prompt for a password when sending mail (though one could probably be hacked-together with half an hours work – after the other 10 hours needed to learn emacs lisp).

You can avoid keeping a password in your initialization file by using a .netrc file.

smtpmail’s documentation can be found here .

If things start not working you might like to use the source – but be careful, some older versions of smtpmail don’t support starttls.

April 27, 2008 at 7:51 pm 4 comments

Emacs link

http://xahlee.org/emacs/emacs.html
seems to contain quite a lot of information about making emacs keybindings more ergonomic as well as a lot of general emacs tips.

Lots of general emacs tips:

http://steve.yegge.googlepages.com/effective-emacs

March 15, 2008 at 1:45 am Leave a comment

Emacs – select entire buffer macro

You can use the mark-whole-buffer. This is bound to C-x h by default.

March 15, 2008 at 12:00 am 1 comment

Older Posts


May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031