Posts Tagged ‘ido’

I’ve written a new article about how to query multiple databases using db-mode. It demonstrates quickly selecting between multiple databases using ido and you may be surprised to learn that it using a mechanism very similar to my directory aliases. This is a follow-up to my page on emacs db mode.

Why Should You Be Interested?

If you need to work with multiple databases and you like using emacs then the page is especially for you. Go take a look! It also has a good example of using the emacs mode line, in this case to display which database you are currently connected to. And finally it is another example of using ido which if you haven’t tried yet, you really should.

About The Code

The code is designed to work with my own db-mode as that is what I use but it could be easily adapted for use with sql-mode using the enter-db function from one of my earlier posts.

The preamble would be something like this:

;; ...
(let ((sql-sybase-program "/usr/bin/isql")
      (sql-server db-server)
      (sql-database db-database)
      (sql-user db-user)
      (sql-password db-password))
;; ...

Ian Eure also has a post on working with multiple databases here. It uses a new buffer for each database which is probably preferable to killing the connection.

Read Full Post »

A few weeks ago when I was talking about autocomplete and dabbrevone of my commenters asked if I had tried hippie-expand. My response was no, but I should take a look as it might allow me to input buffer names more quickly which is something I often need to do.

Following the recipe from the emacs wiki, I tried this:

(global-set-key [(meta f5)] (make-hippie-expand-function
                               try-complete-file-name) t))

After some experimentation, the limitation is obvious. I usually want to complete the entire filename including the path but I can’t remember what the path begins with.

The next thing I thought about was removing *Messages* and *Buffer List* from dabbrev-ignored-buffer-names. Unfortunately, I still need to complete from the beginning of the path but this is generally useful so I’m going to keep it. Really, I want to be able to select any part of the filename and complete from that. Sounds like a job for ido.

First I need a method that returns all buffer names and filenames.

(defun get-files-and-buffers ()
  (let ((res '()))
    (dolist (buffer (buffer-list) res)
      (let ((buffername (buffer-name buffer))
            (filename (buffer-file-name buffer)))
        (unless (string-match "^ *\\*.*\\*$" buffername)
          (push buffername res))
        (when filename (push filename res))))))

Then I can use ido to select between them which is perfect.

(defun insert-file-or-buffer-name (&optional initial)
  (let ((name (ido-completing-read "File/Buffer Name: "
                                   nil nil initial)))
    (when (and (stringp name) (> (length name) 0))
      (insert name))))

(global-set-key (kbd "<f2> i b") 'insert-file-or-buffer-name)

Read Full Post »

Emacs-fu Emacs Tips

Emacs-fu started a great post requesting little tricks. I gave my own response, covering cut-and-paste, ido mode, uniquify and tidy backups. Da Zhang has a nice summary of some of the other tips.

Using/Extending Core Libraries

There are a few emacs libraries that store current state in global variables. For example, ido stores the list of current matches in ido-matches. Accessing this variable while filtering using ido can be a little convoluted. I gave an example of how to do this in Shell Command on Multiple Buffers.

Dabbrev also uses global variables although it provides [internal] functions for completing an abbreviation. I have a complete example at Autocomplete with a Dabbrev Twist but the core is very simple:

(let ((dabbrev-check-all-buffers t))
  (dabbrev--find-all-expansions <abbreviation> t))

Multi-file Search/Replace

I really liked this post from Ian Eure demonstrating how to do multi-file search and replace in emacs. I frequently see emacs proponents saying its awesome and you’ll know when you reach emacs nirvana so it is nice to see a practical demonstration of emacs power. And of course I know it is possible in shell but the simplicity and the interactive nature of emacs makes this a much more pleasant experience. A quick summary:

  • M-x find-grep-dired RET <pattern> (put matching files in dired buffer)
  • m .php$ RET (mark all php files)
  • Q <pattern> RET <replace string> (run query-replace on marked files)
  • C-x s (save all modified files)

Emacs Popularity

So first of all I found this post referring to a thread where a guy says he recommends nano as he has used Unix-like systems that don’t have vi. Hmmm… okay, and then that post has this one from 2007 in the auto-generated links list about Emacs losing in popularity.

And from there I get to this one which has a poll where 56% of the almost 750 respondants chose vim1 as their favourite Linux text editor compared to 9% choosing emacs. Of course it is a highly unscientific result, but do you think more than 6 times as many people use vim as emacs?

1. Fair enough – it is a fine editor

Read Full Post »

I really appreciate all of the comments that people leave on this blog. Occasionally, someone drops by and leaves an great comment with an incredibly useful tip.

shell-command and prefix argument

The first tip I’d like to highlight was at the end of a comment by Steve Vinoski. I didn’t realise how useful it would be when I first saw it but now I find it indispensable.

The tip was that using a prefix argument (i.e. pressing C-u before the command) before the synchronous shell calls inserts the output at point. Without the prefix, the output is (far less usefully) dumped in the mini-buffer.

One thing I use this for is for creating Makefiles where I need to pull in the list of headers and source files. I can now type C-u M-! ls *.H<RET>

             b.H \
             c.H \
             ... \

Filtering ido results

Another thing I didn’t know about was that it is possible to filter ido results. Thanks very much to Reynaldo for pointing this out.

Read Full Post »


Get every new post delivered to your Inbox.