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

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

Re: [h-e-w] Shortcuts?


From: Chuck Siska
Subject: Re: [h-e-w] Shortcuts?
Date: Thu, 28 Feb 2002 11:13:45 -0800

chris --

try this attached .el file.  it lets you follow a M$ shortcut
from dired to the target file or directory.  it works on
M$Wind98. if M$ hasn't been too squirrely, it will work for you.
it binds 'F' (as opposed to the normal 'f') to do this.
cheers.

-- chuck

address@hidden wrote:
> address@hidden writes:

>   > Since Emacs on windows doesn't seem to follow shortcuts, is
>   > there some simple way to define some shortcuts when finding
>   > files? Many of my documents rest fairly deep in my folder
>   > structure, so navigating from one to the other can be
>   > painfully slow... particularly when C-x C-f starts out in the
>   > home folder... even being able to change that so it would
>   > begin in a specific folder would be a partial workaround...

>   You can change the "Start in:" field of your desktop shortcut
> if you like.  You can even make multiple instances each with a
> different value (and name!) if you like. Not the way I'd do it.

>   C-h v default-directory should steer you toward the "cd"
> function which might help.

>   emacs also recognizes environment variables.  Use $NAME to
> access the file defined by the NAME environment variable.

>   You can use "M-x setenv" to set variables within emacs or
> (setenv "FILES" "d:/direct/subdir/") in your .emacs

> note: be careful when dealing with spaces and backslashes 

-- 
                                           |\_/\_.-'""``:-._       
What is life without looking for           . . `; -._      )-;-,_`)
the next cute little bug to play with?     v_,-    _  ),(,.\  ``-' 
                                          _.- _.,-_/ /  ((.'       
-- address@hidden  `<}:..     ((,.-'   ((,/
;;; -*- Emacs-Lisp -*- 
;;; cs-shortcut.el -- Visit file via an M$Wind shortcut file in Dired.
;; Time-stamp: <2002-02-28 11:03:12 Chuck Siska>
;
;;; Author: Chuck Siska <address@hidden>

; This file (consisting of these 3 functions) will bind in Dired the "F"
; key if it is undefined (which is typically the case) to a function
; which will read an M$Wind shortcut file, extract the shortcut's target
; file, and then visit that file as if the user typed "f" (which is the
; normal Dired file visiting key).

; During this process, a temporary buffer will be created, called
; "*cs-shortcut*" into which the shortcut file will be read.  (Note, we
; could kill this buffer after processing, but we prefer to leave small
; amounts of evidence for debugging purposes -- there is always a next
; bug;-)

; These functions have been tested on an M$Wind98 system -- your mileage
; may vary -- but we hope it doesn't.  Note that M$ is notorious for
; arbitrarily changing things around on each release in order to protect
; the favored (which may not include you;-)

; The cs-dired-find-file-via-shortcut function is a cheap modification
; of dired-find-file.  It can be called interactively just like its
; namesake.

; Note, all this is a quick hack.  While it seems to be working for us,
; there is every reason to expect more gremlins in your neck of the
; woods, so tighten your belt buckaroo.  But, perhaps we exaggerate.

;; We use the dired mode keymap, so we need dired.
(require 'dired)

; Here, we grab the target name from the shortcut file.  

(defun cs-find-filename-in-shortcut ( shortcut-filename )
  "Return target absolute path and filename from M$Wind shortcut.
Creates and fills buffer *cs-shortcut* with the shortcut's guts."

    (save-excursion
      (let ((snip1 "")
            (snip2 "")
            (snip3 "" )
            (target-filename nil)
            (buf (get-buffer-create "*cs-shortcut*")))
        (set-buffer buf)
        (erase-buffer)
        (insert ";; Temp Buffer to extract target absolute path and filename\n"
                ";; from M$Wind shortcut.\n"
                ";; Created " (current-time-string) "\n"
                ";; Shortcut File: '" shortcut-filename "'\n"
                ";; Binary data from shortcut file follows:\n\n")
        (insert-file-contents shortcut-filename nil nil nil)
        (let ((pos1 (search-forward snip1))
              (pos2 (search-forward snip2))
              (pos3 (search-forward snip3)))
          (buffer-substring-no-properties (+ pos2 0) (1- pos3))))))

; Note that one way to add the follow-shortcut functionality to dired is
; to directly modify the dired-find-file function so that typing "f" on
; a dired file line will automatically check the ".lnk" ending and
; follow the shortcut if my cs-find-filename-in-shortcut function finds
; a filename.  However, since this is a quick hack and it is unclear how
; effective this is for all M$Wind variants, creating a separate dired
; function and binding it to its own dired key sequence seems the
; prudent path to enlightenment.

(defun cs-dired-find-file-via-shortcut ()
  "In dired, visit the file indicated by the shortcut on this line."

  (interactive)
  (let ((shortcut-file-name (file-name-sans-versions (dired-get-filename) t)))
    (if (file-exists-p shortcut-file-name)
        ;TBD -- here is where to test for ".lnk" ending of shortcut-file-name.
        ; if it doen't end this way -- tell user and abort.
        (let ((file-name (cs-find-filename-in-shortcut shortcut-file-name)))
          (find-file file-name)
          (if (file-symlink-p file-name)
              (error "File is a symlink to a nonexistent target")
            (error "File no longer exists; type `g' to update Dired 
buffer"))))))

; Note, a better way to deal with binding a dired key is to make this
; interactive and let the user select a letter to bind, leaving "F" as
; the default choice.  But we are lightning fast and light as a feather,
; so our work is done here and we're riding off into the sunset while
; leaving the local townsfolk to continue the good work.  Adios.

(defun cs-install-dired-find-file-via-shortcut ()
  "Bind (but don't rebind) the 'F' key in Dired to the shortcut-following
version of dired-find-file called cs-dired-find-file-via-shortcut."

  (let ((map dired-mode-map)
        (target-key "F"))
    (if (keymapp map)
        (let ((current-key-binding (lookup-key map target-key)))
          (if (eq 'undefined current-key-binding)
              (define-key map target-key 'cs-dired-find-file-via-shortcut)
            (message (format "*** Bind Failed: Dired already has '%s' key bound 
to %s"
                             target-key current-key-binding)))))))

; Here we attempt to install the 'F' key to do the shortcut-following thing
; in Dired, but only after Dired has been loaded.

(eval-after-load "dired"
  '(cs-install-dired-find-file-via-shortcut))

reply via email to

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