;;; -*- lexical-binding: t -*- ;; This file: http://user.it.uu.se/~embe8573/conf/emacs-init/navigate-fs-keys.el ;; zsh companion: ~/.zsh/navigate-fs ;; http://user.it.uu.se/~embe8573/conf/.zsh/navigate-fs (require 'cl-macs) (require 'files-my) (require 'super) (require 'w3m-bookmark) (require 'sudo-user-path) (defun do-show-file (file) (interactive "ffile: ") (let ((this-buffer (current-buffer)) (target-buffer (find-file-noselect file) )) (if (eq this-buffer target-buffer) (message "You are already here!") (progn (find-file file) (unless (buffer-modified-p) (revert-buffer t t nil)) ; IGNORE-AUTO NOCONFIRM PRESERVE-MODES )))) (defun shortcut-to-file (key-prefix key file &optional file-prefix) "Make shortcut with key KEY-PREFIX KEY to FILE-PREFIX FILE." (let*((key (format "%s%s" key-prefix key)) (file-dir (or file-prefix "~")) (file (expand-file-name file file-dir))) (global-set-key key (lambda () (interactive) (do-show-file file)) ))) (define-prefix-command 'C-j-prefix-name) (super-global-set-key "\C-j" 'C-j-prefix-name) (defun shortcut-to-function (key-prefix key function) (global-set-key (format "%s%s" key-prefix key) function) ) (defun set-keys (ks &optional key path) (let ((key (format "%s%s" (or key "") (car ks))) (the-path (format "%s%s" (or path "") (cadr ks))) (kps (cl-caddr ks))) (dolist (kp kps) (if (= 2 (length kp)) (if (functionp (cadr kp)) (shortcut-to-function key (car kp) (cadr kp)) (shortcut-to-file key (car kp) (cadr kp) the-path) ) (set-keys kp key the-path) )))) (set-keys `("\C-j" ; invoke key "~/" ; base path ( ;; syntax: ("key" "absolute path") where earlier path won't matter ;; ("key" "relative path") where it will ;; ("key" function) - must be interactive lambda ;; notes: * keys are case sensitive (with J = j if there is no J, only j) ;; * normal path stuff works: e.g., ~ and /sudo:user@host:/path ;; - for sudo tho see `sudo-user-path' ;; * it can be nested *deep* - make it mnemonic! ;; these are not everyday shortcuts! E.g., ;; C-j e w k -> Emacs w3m keys ;; -> ~/.emacs.d/emacs-init/w3m/w3m-keys.el ("." (lambda () (interactive) (dired-jump))) ("a" ,(sudo-root-path "/etc/apt/sources.list")) ("b" "public_html/books/books.bib") ("B" "~/BIRDS") ("c" "scripts/cols") ;; ("C" "cols/color_sets/normal") ("C" "~/public_html/about/cv/CV") ("d" "~/dafny/sel-sort.dfy") ("D" (lambda () (interactive) (find-file "~/DIARY") (auto-fill-mode 0))) ("F" ,(sudo-root-path "/etc/fstab")) ("f" "public_html/FILM") ("H" "HOMES") ("s" "js" ( ("." ".") ("b" "js-bomb.el") ("B" "js-buffer.el") ("d" "js-door.el") ("D" "js-draw.el") ("g" "js-grid.el") ("i" "js-init.el") ("j" "johnny-solver.el") ("k" "js-keys.el") ("m" "js-move.el") ("p" "js-position.el") ("q" "js-start-and-quit.el") ("s" "js-start-and-quit.el") ) ) ("J" "jargon/JARGON-4.4.7") ("i" (lambda () (interactive) (split-window-horizontally))) ("I" ,(sudo-root-path "/etc/inittab")) ("K" ,(sudo-root-path "/etc/console-setup/remap.inc")) ("k" "articles/kon-tiki" ( ("." ".") ("b" "kon-tiki.bib") ("k" "kon-tiki.tex") ("m" "Makefile") ("t" "kon-tiki.txt") )) ;; ("k" ,(sudo-user-path "/etc/default/console-setup")) ("l" ,(sudo-user-path "/etc/rc.local")) ("m" ".mailrc") ("M" "~/.mplayer/input.conf") ("o" "~/public_html/conf/.omx-keys") ("p" "articles/latex/everest.tex") ("P" "everest-plot" ( ("." ".") ("d" "deaths.dat") ("s" "summits.dat") ("m" "Makefile") ("e" "everest.gpi") )) ("h" "public_html/" ( ("c" "style.css") ("e" "emacs.html") ("g" "gnus/index.html") ("i" "index.html") ("I" "irssi/index.html") ("b" "blogomatic" (("p" "index.php") ("b" "index.php") ("i" "index.php") ("c" "m2b.css"))) ("r" "ebc-rss.xml") ("R" "rss.html") ("s" "style.css") ("." ".") )) ("r" "public_html/hs-linux/docs/report/" ( ("\r" ".") ("." ".") ("b" "report.bib") ("r" "report.tex") ("M" "Makefile") )) ("T" ".tmux.conf") ("t" (lambda () (interactive) (show-todos))) ("W" "JOBS") ("w" "public_html/guns/" ( ("\r" ".") ("." ".") ("w" "guns.tex") ("g" "guns.tex") ("b" "guns.bib") ("m" "Makefile") )) ("x" "./" ( ("x" ".xinitrc") ("X" ".Xresources") ("k" ".xbindkeysrc") )) ("z" ".zsh/" ( ("." ".") ("\r" ".") ("a" "apt") ("A" "audio") ("b" "blogomatic") ("B" "be-experiment") ("c" "caps") ("C" "cid") ("d" "dump") ("D" "download") ("e" "error") ("E" "~/.zshenv") ("f" "files-fs") ("F" "files-edit") ("g" "gfx") ("h" "misc-hw") ("i" "ide") ("l" "ls") ("L" "latex") ("m" "map") ("M" "mplayer") ("n" "navigate-fs") ("o" "omx") ("P" "pdf") ("p" "~/.zprofile") ("r" "remote") ("R" "movie") ("s" "spell") ("t" "todo") ("T" "time") ("v" "vt") ("V" "volume") ("u" "mount") ("x" "x") ("z" "zip") (";" "~/.zshrc") ("w" "web") ("W" "wifi") )) ("E" ".temp.el") ("e" ".emacs.d/emacs-init/" ( ("." ".") ("\r" ".") ("a" "~/.emacs.d/lisp/abbrev.el") ("A" "align.el") ("b" "buffer-menu.el") ("B" "my-bibtex.el") ("c" "caps-back.el") ("C" "console-keys.el") ("d" "dired-my.el") (";" "~/.emacs") ("e" "edit.el") ("E" "erc-my.el") ("F" "faces.el") ("f" "files-my.el") ("G" "buc.el") ("g" "gnus/" ( ("." ".") ("\r" ".") ("a" "article.el") ("b" "browse.el") (";" "gnus-my.el") ("g" "gnus-my.el") ("G" "group.el") ("m" "mail.el") ("M" "message-my.el") ("n" "~/News/.newsrc.eld") ("o" "moggle.el") ("p" "~/.emacs.d/passwords.el") ("S" "server.el") ("s" "summary.el") )) ("h" "help-new.el") ("i" "ide/" ( ("." ".") (";" "ide.el") ("\r" ".") ("C" "c-and-cpp.el") ("c" "compile-my.el") ("e" "elisp.el") ("f" "find-command.el") ("i" "ide.el") ("l" "lisp-new.el") ("z" "find-command.el") )) ("I" "isbn.el") ("j" (lambda () (interactive) (call-interactively 'find-elisp-file))) ("k" "global-keys.el") ("K" "kill.el") ("l" "latex.el") ("L" "linux-shell.el") ("M" "Makefile") ("m" "man-my.el") ("n" "navigate-fs-keys.el") ("N" "mode-by-filename.el") ("P" "elpa.el") ("p" "~/.emacs.d/piped-out.txt") ("q" "quit.el") ("r" "revert-buffer-my.el") ("R" "~/.emacs.d/emacs-init/search-regexp-in-files.el") ("s" "scroll.el") ("S" "spell-new.el") ("t" "todo-did.el") ("T" "time-my.el") ("y" "yank-my.el") ("v" "vt.el") ("V" "window-new.el") ("W" "wrap-search.el") ("w" "w3m/" ( ("." ".") ("\r" ".") ("a" "autologin.el") ("b" "bookmarks.el") ("B" ,w3m-bookmark-file) ("d" "dl.el") ("k" "w3m-keys.el") ("s" "w3m-unisearch.el") ("w" "w3m-my.el") )) ("x" "xsel.el") ("z" "ide/find-command.el") )) ("G" "~/gmt.conf") ("g" "" ( ("g" ,(sudo-user-path "/etc/default/grub")) ("c" ,(sudo-user-path "/boot/grub/grub.cfg")) )))))