Created
August 5, 2012 08:58
-
-
Save sky-y/3263051 to your computer and use it in GitHub Desktop.
Emacs: Open the file which filename is pointed in an other window or dired
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Open the file name being pointed in an other window or dired | |
;; reference: http://kouzuka.blogspot.com/2011/02/emacsurlfinder.html | |
(defun my-directory-or-file-p (path) | |
"return t if path is a directory, | |
return nil if path is a file" | |
(car (file-attributes path))) | |
(defun my-open-emacs-at-point () | |
"open the file with opening emacs" | |
(interactive) | |
(require 'ffap) | |
(let ((file (or (ffap-url-at-point) | |
(ffap-file-at-point)))) | |
(unless (stringp file) | |
(error"No file or URL found")) | |
(when (file-exists-p (expand-file-name file)) | |
(setq file (expand-file-name file))) | |
(message "Open: %s" file) | |
(if (my-directory-or-file-p file) | |
(dired-other-window file) | |
(find-file-other-window file)) | |
)) | |
(global-set-key (kbd "\C-c o") 'my-open-emacs-at-point) | |
;; double click | |
(global-set-key [double-mouse-1] 'my-open-emacs-at-point) | |
(global-set-key [double-down-mouse-1] 'ignore) ; mouse-drag-region |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment