Skip to content

Instantly share code, notes, and snippets.

@mdsib
Last active April 12, 2017 00:43
Show Gist options
  • Save mdsib/a8658207297bbe50c516cded105c13d0 to your computer and use it in GitHub Desktop.
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.
@tfrmb
Copy link

tfrmb commented Apr 11, 2017

hi - I think this is exactly what I need! unfortunately executing results in 'Symbol's function definition is void: lexical-let"
With debugger 'on':
Debugger entered--Lisp error: (void-function lexical-let)

EDIT - just found out I needed to add (require 'cl)

Now there is another message after executing 'ms-insert-newest-file'
Symbol's function definition is void: org-insert-link

EDIT 2 -Apparently need a more recent org-mode version? Will install later and try again.

EDIT 3 - Installed the latest org version and indeed something is happening now, but it is still not working as expected. The error is gone though. If I am executing in a txt file something is created after being prompted with description: -> [[Downloads/tst]] it should be [[file:Downloads/tst.txt]] to work in org though.
Doing the same in an org file doesn't result in anything.
Org version 9.05 and Emacs 24.5.1

EDIT 4 - Now finally tried it on the target device that has a more recent Emacs version 25.1.1 and updated Org to 9.05
Directory where emacs should be looking is /media/mmc1/DCIM so I updated global-set-key to :
(global-set-key (kbd "C-c C-r") (ms-insert-newest-file "/media/mmc1/DCIM"))

Tried again and the same issue with a .org file. Nothing happens.
The .txt file shows [[../../media/mmc1/DCIM/20170411_01.jpg]]

That is already quite promising, but it should be [[file:/media/mmc1/DCIM/20170411_01.jpg]] and of course also working with an org file - the picture in the 'link' is indeed the latest picture added in the directory. Hope you can find the cause of the issue.

@mdsib
Copy link
Author

mdsib commented Apr 12, 2017

hi - I think this is exactly what I need! unfortunately executing results in 'Symbol's function definition is void: lexical-let"
With debugger 'on':
Debugger entered--Lisp error: (void-function lexical-let)
EDIT - just found out I needed to add (require 'cl)

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 in global-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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment