Archive for the 'Emacs' Category
Do you want to show off emacs?
Take a look at this screencast. Just amazing, I found it while reading the emacs wiki page of cedet.
Elisp func to create a dummy admin.py
While writing a django app, I faced the tedious task of updating the corresponding admin.py file for the models I was writing. Because I didn’t want to customize any of the admin options just yet all I had to do is insert new register entries on the file (one for model). I grew tired of this pretty soon so I wrote this elisp function to update an admin.py file easily. Hope this helps somebody
(defun rl/django-admin-all-models() (interactive) (let ((content " ")) (with-temp-buffer (insert "from models import *\n") (insert "from django.contrib import admin\n\n") (let ((text-start (point))) (insert-file-contents "models.py") (keep-lines "^class.*$" text-start (point-max)) (while (re-search-forward "^class \\(\\w+\\).*" nil t) (replace-match "admin.site.register(\\1)")) (write-file "admin.py" nil)))))
A word of warning: this will override your current admin.py
python and emacs: the rope way
If you follow Planet Emacsen you have probably read a couple of great posts about emacs and python.
Ryan McGuire’s EnigmaCurry blog has a post about using Emacs as a powerful Python IDE, and later about using Autocomplete.el: code completion in emacs. The heart of both posts is rope and ropemacs. Rope is a great!, go to rope’s website for a full feature listing (e.g. autocompletion, refactoring, pydoc, etc.)
A simple post about what you need to install and how you have this post from Edward O’Connor.
Also, if you use yasnippet for templates you may also find interesting Ian Eure’s post about Disabling Python-mode’s skeletons would be also very useful.
Why did I stop using tabs on emacs?
A long (long!) time ago I used to be trapped on the Windows world,
surfing the Web using Microsoft Internet Explorer… and I hated
it. It was an absolute mess having more than 5 windows open, so I
didn’t open more than 3. And then I found Firefox with it’s tabs, I
just loved it.
Fast forward to the present, on almost anything I do using a GUI I
want to be able to use tabs, even on Emacs. I was a huge fan of
elscreen,
it’s a nice package that creates and manages tabs on emacs, nicely
integrated with emacs-w3m (although
emacs-w3m have their own tabs), dired and a few more. I wrote some
elisp code to integrate it with
erc and
jabber.el. So what happen?
Tabs are a great way of organizing and making accessible content, don’t
get me wrong, but on emacs you have the power of the minibuffer, and matching it with
ido-mode feel more emacsy for me than tabs. It does fuzzy
auto-completion on the minibuffer when opening a file or switching
buffers. And when you begin to feeling comfortable using it, tabs (at
least for me) become almost useless.
If what I said earlier doesn’t convince you, I recommend you to watch
Stuart Halloway’s great What You
Can Learn From ido.el. It greatly
motivated me to take a deep look at ido-mode.
Yasnippet for C style comments
Are you using yasnippet right?
No? Well, in a nutshell is an awesome template system for Emacs, I
really recommend it. The template language is very easy to learn and
there are templates for a lot of programming languages.
Yasnippet stores your snippets in the filesystem, a single snippet per
file and inside a directory structure that mirrors the major mode
hierarchy. For example, the snippet for the using namespace std C++
idiom is stored in a file named using, and it’s located in the
directory snippets/text-mode/cc-mode/c++-mode. The file name (in
this example using) is used as the key for the expansion. You know,
convention over configuration .
Because yasnippets uses filenames as keys, you face filesystem’s
naming restrictions, and this is a problem if you want to define a
snippet for C comments, you can’t name a file /* for obvious
reasons. What do you do then? Well, yasnippet allows you to define
your snippets in elisp code directly, so if you want to create your C
sytle comments template, you can do something like this
;; $0 defines where the cursor will be left after the expansion (yas/define 'cc-mode "/*" "/* $0 */") (yas/define 'cc-mode "/**" "/**\n * $0\n **/")
The first argument is the major mode where this snippet will be available, the second is the key you will use to expand the template, and the last argument is the template itself.
For more about writting snippets for this system, go here
Emacs ps (v.23)
Another post about a new feature in emacs 23. This new feature is proced, and from the NEWS entry:
** proced.el provides a Dired-like interface for operating on processes. Proced makes an Emacs buffer containing a listing of the current processes (using ps(1)). You can use the normal Emacs commands to move around in this buffer, and special Proced commands to operate on the processes listed.
I found this great!, another reason to stay inside your emacs
Here is a screenshot from my machine:
Emacs daemon! (v.23)
I use emacs 23 (alpha version). It’s still under heavy development and considered not for general consumption but you know, emacs “alpha” is like “service pack 2″ for others; it haven’t misbehave once.
One of the greatest features of this version of emacs is the multi-tty support, and it means that you can have with a single emacs server both an emacs client running in text-mode and another client running in graphic-mode.
One of the pitfalls of my emacs installation is that I load several libraries so it takes a while to start-up (not like eclipse, I mean a while like 5 seconds). It would be wonderful if emacs could somehow be ran as a daemon and then you could run your emacsclient and have instant access…
Well, it can!. Emacs has a new option –daemon that runs emacs on the background as a server, so you only need to call emacsclient. Emacs rules!
Insert a path into the current buffer
Sometimes I need to insert into a buffer a path (e.g. /home/user/.emacs) and I want to use emacs’ excellent completion capabilities. It turns out to be pretty easy to implement this function in elisp. Here is the snippet:
(defun insert-path () "Inserts a path into the buffer with completion" (interactive) (insert (expand-file-name (read-file-name "Path: "))))
As always, any comments on the code above are more than welcome
Another way of doing it suggested by Peter Mielke is:
(defun insert-path (file) "insert file" (interactive "FPath: ") (insert (expand-file-name file)))
I think this is a better option because uses interactive built-in support for file input rather than using the read-file-name function. Thank you for the tip Peter
How to type when using emacs?
On emacs.help a very interesting thread about you, your fingers and emacs is taking place. Is no secret that emacs extensive use of “key combos” is both a blessing and a curse. While they make almost every feature of emacs a few keystrokes away, they can also put your fingers and wrist under continus stress
Between the suggestions to improve the situation are: swap caps lock and control, swap alt and ctrl, change your keyboard layout to dvorak, etc.
Here is the link to the gmane archive of the thread with more links and more comments.
Don’t forget that emacs.help is a public mailing list where you can take part
. Go ahead and subscribe.
