help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: opening a filename that appears in a buffer?


From: Xah
Subject: Re: opening a filename that appears in a buffer?
Date: Thu, 22 May 2008 09:31:22 -0700 (PDT)
User-agent: G2/1.0

On May 20, 12:53 pm, ljp <address@hidden> wrote:
> Hello all,
>
> I'm relatively new to emacs, and it is gradually becoming the central
> fixture through which I do all of my programming.    One thing I find
> myself doing often is executing a shell command in a shell buffer, and
> then wanting to open a file that was listed in the output of the shell
> command.   To do this right now I manually select the filename and
> paste it into the minibuffer for C-x C-f.  Is there an easier way?
> Like, maybe, a command that is able to pick out a filename from the
> buffer when the cursor is in (but not necessarily at the start of)
> that filename, and then open the file in a new buffer?
>
> Thanks!  I've looked through documentation, but I haven't found
> anything like this.

Some extra tips:

change keybinding of M-x to M-a, so it's right under finger tip.

Change keybinding of M-! to Meta-shift-a, so that M-a is to execute
emacs cmd, and with shift down it runs a shell cmd.

Use alias to shortern the command “shell” to just “sh”.

The C-x C-f is to open a file, remap it to just M-f, since Meta is
right under thumb.

Give find-file-at-point a shortcut of Meta shift f. So that M-f is to
opens file, M-f with a dir path gives you dired, M-S-f opens the file
under cursor.

These are my personal settings. Here's code examples:

(defalias 'sh 'shell)

(global-unset-key (kbd "C-x C-f")) ; find-file
(global-unset-key (kbd "C-x d")) ; dired. (use find-file instead)

(global-set-key (kbd "M-f") 'find-file) ; was forward-word
(global-set-key (kbd "M-F") 'my-find-file-at-point) ; was nil

(global-set-key (kbd "M-a") 'execute-extended-command) ; was backward-
sentence
(global-set-key (kbd "M-A") 'shell-command)

i've also modified my ffap so that, when i view web logs which has
relative paths based on web root dir (as opposed the real root dir), i
can still use ffap to open the right file.

(defun my-find-file-at-point ()
 "Same as `find-file-at-point' but prepend path if root file.
If the path start with “/” and not "/Users/", then prepend it with “~/
web”."
 (interactive)
 (let (ff)
   (setq ff (thing-at-point 'filename))
   (when (and
          (equal "/" (substring ff 0 1))
          (not (equal "/Users/" (substring ff 0 7))))
     (setq ff (concat "~/web" ff)))
   (find-file ff)
   )
 )

I have several emacs tutorial on how to define arbitary keybindings,
and a full shortcut set based on ergonomic priciples. It's on my
website you might find interesting.

  Xah
  address@hidden
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]