8

I have a copy of emacs that I use on a couple of different (windows) computers from a thumb drive, and I am wondering if it is possible to create something that is sort of the equivalent of a bash alias or symlink within emacs? Something that I could use within find-file is the main thing that i'm looking for, so for example: C-f <some link> would take me somewhere. Currently I have to add a new defun every time i get to a new computer, which is just kind of a pain and I would swear i've seen this somewhere, but months of googling have turned up nothing.

What i've got right now is something like:

(defun go-awesome ()
   "Find my way to my work home"
   (interactive)
   (find-file "c:/cygwin/home/awesome"))

But that feels increadibly overdone and hacky for just visiting a fairly hacky for just visiting a file that i visit semi-regularly. And it requires a lot of effort to set up a new file.

The biggest problem with it though, in my opinion is that it doesn't fit in my workflow. When i want to visit a file i always do C-x C-f, and if i realize that "hey i'm at work" i then have to C-g M-x go-awesome. Perhaps it would be more clear if i said that i wanted to be able to do something that is the equivalent of an ln -s /some/awesome/dir but internal to emacs, instead of built into the OS, so that C-x C-f ~/awesome/some/sub/dir would work on windows or anywhere else.

Drew
  • 29,895
  • 7
  • 74
  • 104
quodlibetor
  • 8,185
  • 4
  • 35
  • 48
  • Please explain more of what you are looking for. Are you re-writing functions when you go to a new computer (i.e., you don't have your .emacs file on the thumb drive)? – dwj Oct 06 '08 at 21:36
  • What functions are you rewriting? (What is the purpose of these functions, to open certain files? e.g. (find-config-file)?) Do you want to go "C-f config-file" and have it automatically load blah.conf from a location that depends on which machine you're using? – Matt Curtis Oct 07 '08 at 03:27

7 Answers7

12

I'm not really clear on what you're asking for. I store my commonly-used files in registers in my .emacs:

(set-register ?c '(file . "c:/data/common.txt"))
(set-register ?f '(file . "c:/data/frequent.txt"))

Then I can jump to a file with jump-to-register (C-x r j):

For example, "C-x r j c" takes me to c:/data/common.txt (loading it if necessary).

Is that what you're looking for?

cjm
  • 61,471
  • 9
  • 126
  • 175
2

If you want an alias to a function, you use defalias:

(defalias 'nuke 'delete-trailing-whitespace)

But if you're complaining that Emacs's function names are too long, you should look into partial-completion-mode. With that turned on,

M-x d-t-w [RET]

will run delete-trailing-whitespace.

cjm
  • 61,471
  • 9
  • 126
  • 175
2

Here's what you need --

  • Define bookmarks that correspond to contexts you want to revisit. With Bookmark+ this need not be just a file. It can also be a whole Emacs desktop or a Dired buffer with its markings (saved), a set of other bookmarks,...

  • Use Icicles together with Bookmark+. Whenever you use C-x C-f etc. to visit a file, you can also visit a file or directory bookmark (complete against the bookmark name). Just hit C-x m when you are in the minibuffer for file-name completion.

Drew
  • 29,895
  • 7
  • 74
  • 104
  • Thanks for the pointers to these amazing emacs packages. Glad to see that icicles is a package available for Ubuntu (starting with Lucid). Bookmark+ takes some silly manual steps to install, but well worth it.... – nealmcb Aug 11 '12 at 23:45
0

This blog entry defines almost exactly what I wanted, basically let's me hit $ in the minibuffer and then presents me with a list of my bookmarks that I can jump to. I might tweak it so that if I specify a file bookmark it takes me to the file instead of the directory, but that's a nit, especially considering that the file the bookmark is of tends to be at the top of the list anyway.

quodlibetor
  • 8,185
  • 4
  • 35
  • 48
0

I what you want is open a given file with just a command you can define a keyboard macro. This macro open the file ~/.bashrc

 C-x( # start defining the macro
 C-x C-f ~/.bashrc   
 C-x )  # end definition

Then you can name this macro

M-x name-last-kbd-macro
visitbashrc   #give it a name

then you can call it by name M-x visitbashrc

You can save the definition to a file, .emacs for instance by visiting this file and inserting the definition in it, with

M-x insert-kbd-macro
stephanea
  • 1,108
  • 8
  • 10
0

I have this setup below. So for example, if I want to find a file on my desktop (D:/Desktop), I type F3 j F3, and no matter what path I started with, the minibuffer now says "D:\Desktop\" and I'm ready to type any filename on the Desktop. I set my shortcut to j, k, l, i b/c those are close to where my left hand is, but with this setup, any shortcut up to 4 letters will work. So you can add an entry for your "awsome" file, say "awe", and you can type F3 awe F3 enter to visit your file. Don't know whether this is what you are looking for; but this save me a lots of typing ;)

(global-set-key [f3] 'ffap)

;comcplete shortcut in minibuffer
(define-key minibuffer-local-completion-map (kbd "<f3>")
                      'complete-minibuffer-path) 

(defun complete-minibuffer-path ()
  "Extension to the complete word facility of the minibuffer by
replacing matching strings to a specific path"
  (interactive)
  (setq found t)
  (cond
     ; just add new entries if needed; shortcut up to 4 letters will work
     ((looking-back "j" 5 nil) (setq directory "D:/Desktop/"))
     ((looking-back "k" 5 nil) (setq directory "D:/Documents/"))
     ((looking-back "l" 5 nil) (setq directory home-dir))
     ((looking-back "i" 5 nil) (setq directory "D:/Programs/"))
     (t (setq found nil)))
  (cond (found (beginning-of-line)
                (kill-line)
                (insert directory))
         (t (minibuffer-complete)))) 
polyglot
  • 9,945
  • 10
  • 49
  • 63
-1

I Moved this into the original question, but i'm leaving it here because people responded to it already

That's way better than what i've got, but what i feel like probably exists is something that would replace, for example:

(defun nuke ()
   "alias delete-trailing-whitespace"
   (interactive)
   (delete-trailing-whitespace))

and feel less hacky, and like it was actually doing what it was supposed to be doing, instead of doing something really heavy for what feels like something that should be really light.

Does that make sense?

Your assign to registers might actually be better than what i'm looking for, though.

quodlibetor
  • 8,185
  • 4
  • 35
  • 48
  • This really should have been added to the question. (Or maybe clarify the question and then post this as an answer.) – cjm Oct 07 '08 at 06:02