Last active
April 12, 2017 00:43
-
-
Save mdsib/a8658207297bbe50c516cded105c13d0 to your computer and use it in GitHub Desktop.
Creates a keybinding that links to the most recently edited file of a directory.
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
(defun ms-filter-dirs (filelist) | |
(remove-if (lambda (file) (file-directory-p file)) filelist)) | |
(defun ms-newest-file (dir) | |
(reduce (lambda (accum file) | |
(if (file-newer-than-file-p file accum) | |
file | |
accum)) | |
(ms-filter-dirs (directory-files dir t)))) | |
(defun ms-insert-newest-file (dir) | |
(lexical-let ((dir dir)) | |
(lambda () | |
(interactive) | |
(org-insert-link :link-location (concat "file:" | |
(ms-newest-file dir)))))) | |
(global-set-key (kbd "C-c C-S-l") (ms-insert-newest-file "~/Downloads")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, that's part of cl. All it's doing is allowing that dir parameter from
ms-insert-newest-file
to be used in the lambda function it's returning. You can see in the initial gist I used to just create the function inglobal-set-key
. You can do that if you don't want to include cl.I'm going to remove the relative filename conversion and append "file:" to the link, that should put the generated link in the correct format.