Skip to content
Newer
Older
100644 83 lines (75 sloc) 3.05 KB
2e54ede @vjohansen misc
authored
1 (require 'w32-utl)
e3157f4 @vjohansen added vj-csharp-mode-hook. Added missing require calls.
authored
2 (require 'findr)
2e54ede @vjohansen misc
authored
3
4 ;; Example: (vj-get-cached-data "~/x" (lambda () '("test")) 10)
5 ;; - Load data from x file if newer than 10 days otherwise build it via the
9a39e6f @vjohansen Updated README, moved mpg123.el to site-lisp/, add more modes to prog…
authored
6 ;; lambda and store in the filename given.
7 ;; Always return data either cached or built via the function.
2e54ede @vjohansen misc
authored
8 (defun vj-get-cached-data (filename builder-func rebuild-days)
9 (let* ((exists (file-exists-p (expand-file-name filename)))
10 (mtime (if exists
11 (time-to-seconds (time-since
12 (nth 5 (file-attributes filename))))))
9a39e6f @vjohansen Updated README, moved mpg123.el to site-lisp/, add more modes to prog…
authored
13 (age (if exists (/ mtime (* 24 60 60))))
2e54ede @vjohansen misc
authored
14 result)
15 (if (and exists (< age rebuild-days))
16 (load-file filename) ;sets result
17 ;; else: we need to build the data
18 (require 'recentf)
19 (setq result (funcall builder-func))
20 (with-temp-file filename
21 (insert (format ";; Emacs was here. Generated %s\n"
22 (current-time-string)))
23 (recentf-dump-variable 'result)))
24 result))
25
26 (defun vj-w32-apps-build ()
27 (interactive)
28 "Build the command list by recursively look for .lnk files"
29 (let ((files
30 (append
31 (findr "\.lnk$" (w32-utl-special-folder "StartMenu"))
32 (findr "\.lnk$" (w32-utl-special-folder "AllUsersStartMenu"))))
33 link-name)
34 (message "Please be patient. Scanning disk...")
35 (setq w32-apps-list
36 (mapcar
37 (lambda (file)
38 (setq link-name (file-name-nondirectory file))
39 (setq link-name (substring
40 link-name 0 (- (length link-name) 4)))
41 (cons link-name (w32-utl-lnk-get-target-and-args file)))
42 files))))
43
44 (defvar w32-apps-list
9a39e6f @vjohansen Updated README, moved mpg123.el to site-lisp/, add more modes to prog…
authored
45 (delq nil (mapcar
46 ;; remove those where exe-path is ""
47 (lambda (x) (if (equal (nth 1 x) "") nil x))
48 ;; input list
49 (vj-get-cached-data "~/.w32-apps.el" 'vj-w32-apps-build 60))))
2e54ede @vjohansen misc
authored
50
51 (defvar anything-source-w32-launch
52 '((name . "Launch Program")
53 (candidates . (lambda () w32-apps-list))
54 ;; (type . program)
55 (action . (("Launch" .
56 (lambda (filename)
57 (let ((f (car filename)))
58 (message "Launch %s" f)
59 (if (equal (file-name-extension f) "url")
60 (vj-os-open f)
61 (vj-w32-launch filename))
62 )))
63 ("Dired" .
64 (lambda (filename)
65 (dired (file-name-directory (car filename)))
66 (dired-goto-file (car filename))))))
67 (requires-pattern . 2))
68 "Source for launching windows apps.")
69
70 (defun vj-w32-launch (app-and-parms)
71 ""
72 (apply 'call-process
73 ; maybe (cdr app-and-parms) should be split on space?
9a39e6f @vjohansen Updated README, moved mpg123.el to site-lisp/, add more modes to prog…
authored
74 (append (list (car app-and-parms) nil 0 nil) (cdr app-and-parms))))
2e54ede @vjohansen misc
authored
75
76 (defun anything-for-apps ()
9a39e6f @vjohansen Updated README, moved mpg123.el to site-lisp/, add more modes to prog…
authored
77 "Preconfigured `anything' for apps."
2e54ede @vjohansen misc
authored
78 (interactive)
79 (anything-other-buffer '(anything-source-w32-launch)
80 "*anything for apps*"))
81
82 (global-set-key (kbd "C-æ") 'anything-for-apps)
Something went wrong with that request. Please try again.