tags:

views:

693

answers:

7

Hi, 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.

+9  A: 

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
A: 

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
This really should have been added to the question. (Or maybe clarify the question and then post this as an answer.)
cjm
A: 

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
+3  A: 

Something that I could use within find-file is the main thing that i'm looking for, so for example: C-f would take me somewhere.

There's bookmarks.

fivebells
A: 

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
A: 

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
A: 

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