Archive for the 'Emacs' Category

keybinding doubts? no more

Just a short one… If you have doubts about emacs keybindings, read here. Is awesome!.

Just as a site note, I found it while looking how to set WindowsKey(Super)-tab as a keybinding for lisp-complete-symbol


(define-key lisp-mode-map [s-tab] 'lisp-complete-symbol)

Really easy :)

Do you use google to find definitions?

UPDATE:For this code to work you need to include the mm-url library. The code is now fixed

If so, here’s a little snippet I wrote for emacs to have all this power just one keystroke away

(require 'mm-url)
(defun google-define-word-or-phrase (query)
  (interactive "sInsert word or phrase to search: ")
  (let* ((url (concat "http://www.google.com.pe/search?hl=en&q=define%3A"
              (replace-regexp-in-string " " "+" query)))
     (definition
       (save-excursion
         (with-temp-buffer
           (mm-url-insert url)
           (goto-char (point-min))
           (if (search-forward "No definitions found of " nil t)
           "No definitions found"
         (buffer-substring (search-forward "<li>") (- (search-forward "<") 1)))))))
    (message "%s: %s" query definition)))

(global-set-key [f5] 'google-define-word-or-phrase)

This uses google’s define: operator to look up for a word or phrase. Copy & Paste this code into your .emacs and with pressinf F5 you will be prompted for your query. Have fun

If you have any comments on the code they will be more than welcome :)

[BEH] How to display info help inside a box

That ASCII-art box is great for many things, specially when used to describe a function, variable or key. The necesary package is boxquote. And to have all its power at your fingertips, a snippet for your .emacs

(require 'boxquote)

(global-set-key (kbd "C-c b y")   'boxquote-yank)
(global-set-key (kbd "C-c b r")   'boxquote-region)
(global-set-key (kbd "C-c b u")   'boxquote-unbox-region)
(global-set-key (kbd "C-c b t")   'boxquote-title)
(global-set-key (kbd "C-c b i")   'boxquote-insert-file)
(global-set-key (kbd "C-c b k")   'boxquote-kill)
(global-set-key (kbd "C-c b s")   'boxquote-shell-command)

(global-set-key (kbd "C-c b b")   'boxquote-buffer)
(global-set-key (kbd "C-c b p")   'boxquote-paragraph)
(global-set-key (kbd "C-c b n")   'boxquote-narrow-to-boxquote)

(global-set-key (kbd "C-c b w")   'boxquote-where-is)
(global-set-key (kbd "C-c b d f") 'boxquote-describe-function)
(global-set-key (kbd "C-c b d k") 'boxquote-describe-key)
(global-set-key (kbd "C-c b d v") 'boxquote-describe-variable)

BEH: eshell and su

With this entry a new category for emacs related posts will begin here. Bits from emacs.help are tips and tricks found while reading the emacs.help mailing list

Well, this tips is how to use su inside eshell

From the post: “…Doing su or sudo su does not work like you expect. This works under the normal shell (M-x shell). I am su:ing quite much …” If you have tried, using su inside eshell is quite paintful, and doesn’t work very well. But, come on, there should be a way of doing it, right?

From the reply: “…Tramp 2.1 supports it. Try “cd/sudo::” in eshell…” And that’s it! you have a fully functional ‘suded’ eshell with completition available.

A quick note: eshell alias

Update: while reading this wiki entry I found that you need to quote your alias only if you are writing it directly on the prompt. On the alias file you don’t quote anything. In fact, you don’t need to modify the alias file by hand because emacs writes it for any alias you define on the prompt.

(This is mostly a personal note but it may be useful to somebody else)

I’m not sure that everybody knows (the manual version I have doesn’t mencion it) but to configure an alias for eshell is as easy as this:

On the .eshell/alias file just add

alias ls ls -la $*

This is a taken from this blog post. You can read there a more lispy way of doing it.

Also, take a look at this interesting this wiki entry