* Elisp: help on string operations for fast file visiting
@ 2016-11-07 16:27 Karl Voit
2016-11-08 8:42 ` Alan Schmitt
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Karl Voit @ 2016-11-07 16:27 UTC (permalink / raw)
To: emacs-orgmode
Hi!
For Memacs[1], I'd like to come up with a very fast Org-mode method to
open files independent of their location on your disk. I accomplished
everything necessary so far. However, I've got issues writing an elisp
function for extracting a file and sending it to a function that calls
the operating system app associated. My elisp knowledge is still too
bad :-(
What I've got is a string (from the lookup) which contains:
(1) nothing
(2) one line like "** <2008-06-17 21:43> [[file:/home/user/dir/2008-06-17 description of file.odp][2008-06-17 description of file.odp]]"
(3) multiple lines like (2) but with different files and links
I'd like to get a "Sorry" message for (1). Easy, if only I know how to
count lines in strings (as opposed to buffers).
For (2) I'd like to call my-open-in-external-app(string).
For (3), I'd like to use the first line just as in (2) as a starter. I
do have some ideas on gracious "error-recovering" on this one but
that's maybe too complicated to code for now: getting rid of
substrings delimited by not-'a-zA-Z0-9' from the end of the link
until a match is found; message in case there is no unique match which
could be found this way.
Could you please help me here? It'd help all users of the file index
module of Memacs.
The mini fragment I have so far is following but the regex seems to
be broken:
#+BEGIN_SRC elisp
(let (
(result (replace-regexp-in-string "\r?\n$" ""
(shell-command-to-string (concat "grep "
"2008-06-17"
" ~/org/memacs/files.org_archive");; hard coded stuff for testing purposes
)
)
)
)
(message (concat "result -> " result))
(re-search-forward " \[\[.+\]\[" nil t 1)
(let (
(firstlink ((match-string 1)))
)
(message (concat "first link -> " firstlink))
)
)
#+END_SRC
[1] https://github.com/novoid/Memacs
--
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
> get Memacs from https://github.com/novoid/Memacs <
https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Elisp: help on string operations for fast file visiting
2016-11-07 16:27 Elisp: help on string operations for fast file visiting Karl Voit
@ 2016-11-08 8:42 ` Alan Schmitt
2016-11-08 9:28 ` Karl Voit
2016-12-21 0:30 ` John Kitchin
2017-01-02 10:00 ` Fast Opening of Memacs Indexed Files (was: Elisp: help on string operations for fast file visiting) Karl Voit
2 siblings, 1 reply; 5+ messages in thread
From: Alan Schmitt @ 2016-11-08 8:42 UTC (permalink / raw)
To: Karl Voit; +Cc: Karl Voit, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 507 bytes --]
On 2016-11-07 17:27, Karl Voit <devnull@Karl-Voit.at> writes:
> I'd like to get a "Sorry" message for (1). Easy, if only I know how to
> count lines in strings (as opposed to buffers).
You could start by doing (split-string the_string "\n" t) (the last 't'
says to omit the empty strings). So you get a list, possibly empty, of
strings.
Would this help for the rest?
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂, Mauna Loa Obs. 2016-09: 401.03, 2015-09: 397.63
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 454 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Elisp: help on string operations for fast file visiting
2016-11-08 8:42 ` Alan Schmitt
@ 2016-11-08 9:28 ` Karl Voit
0 siblings, 0 replies; 5+ messages in thread
From: Karl Voit @ 2016-11-08 9:28 UTC (permalink / raw)
To: emacs-orgmode
* Alan Schmitt <alan.schmitt@polytechnique.org> wrote:
>
> On 2016-11-07 17:27, Karl Voit <devnull@Karl-Voit.at> writes:
>
>> I'd like to get a "Sorry" message for (1). Easy, if only I know how to
>> count lines in strings (as opposed to buffers).
>
> You could start by doing (split-string the_string "\n" t) (the last 't'
> says to omit the empty strings). So you get a list, possibly empty, of
> strings.
>
> Would this help for the rest?
Thanks for the tipp!
John Kitchin sent me some code I have to digest. From the first
look, it should help me to come up with the complete solution I
need. Thanks! I'll report back ;-)
--
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
> get Memacs from https://github.com/novoid/Memacs <
https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Elisp: help on string operations for fast file visiting
2016-11-07 16:27 Elisp: help on string operations for fast file visiting Karl Voit
2016-11-08 8:42 ` Alan Schmitt
@ 2016-12-21 0:30 ` John Kitchin
2017-01-02 10:00 ` Fast Opening of Memacs Indexed Files (was: Elisp: help on string operations for fast file visiting) Karl Voit
2 siblings, 0 replies; 5+ messages in thread
From: John Kitchin @ 2016-12-21 0:30 UTC (permalink / raw)
To: Karl Voit; +Cc: emacs-orgmode
This is a different approach to what I think you want.
Here is what I assume in this:
1. All the things you want to search for are in a file called
archive.org which is in the same directory you are searching for (use an
absolute path if it is not).
2. You have file links that only have a path, i.e. nothing like
file:test.odp::45
3. You want the query to match some part of the path in a file link.
4. if you click on the link you want, it will open the file in the
external program you want it to open in. This will probably work if they
are always absolute paths, and might be a problem for relative paths
(they would need to be correctly converted to absolute paths).
What it does is get all the file links in the archive.org file that
have a path that matches the query. If there is none, you get a message.
If there is one, it opens it as if you clicked on the link. and if there
is more than one, it prompts you with completing read to choose one,
then opens it.
#+BEGIN_SRC emacs-lisp
(defun memacs-file (query)
"Open memacs files by QUERY."
(interactive "sQuery: ")
(with-current-buffer (find-file-noselect "archive.org")
(let ((links (org-element-map (org-element-parse-buffer) 'link
(lambda (link)
(when (string-match query (org-element-property :path link)) link)))))
(cond
((= 0 (length links))
(message "No files found."))
((= 1 (length links))
(org-open-link-from-string
(format "[[file:%s]]" (org-element-property :path (car links)))))
(t
(org-open-link-from-string
(completing-read
"File: "
(mapcar (lambda (link)
(format "[[file:%s]]" (org-element-property :path link)))
links))))))))
#+END_SRC
For a large archive file, you might be better off with a grep solution,
since this has to parse the file first.
Karl Voit writes:
> Hi!
>
> For Memacs[1], I'd like to come up with a very fast Org-mode method to
> open files independent of their location on your disk. I accomplished
> everything necessary so far. However, I've got issues writing an elisp
> function for extracting a file and sending it to a function that calls
> the operating system app associated. My elisp knowledge is still too
> bad :-(
>
> What I've got is a string (from the lookup) which contains:
> (1) nothing
> (2) one line like "** <2008-06-17 21:43> [[file:/home/user/dir/2008-06-17 description of file.odp][2008-06-17 description of file.odp]]"
> (3) multiple lines like (2) but with different files and links
>
> I'd like to get a "Sorry" message for (1). Easy, if only I know how to
> count lines in strings (as opposed to buffers).
>
> For (2) I'd like to call my-open-in-external-app(string).
>
> For (3), I'd like to use the first line just as in (2) as a starter. I
> do have some ideas on gracious "error-recovering" on this one but
> that's maybe too complicated to code for now: getting rid of
> substrings delimited by not-'a-zA-Z0-9' from the end of the link
> until a match is found; message in case there is no unique match which
> could be found this way.
>
> Could you please help me here? It'd help all users of the file index
> module of Memacs.
>
>
> The mini fragment I have so far is following but the regex seems to
> be broken:
>
> #+BEGIN_SRC elisp
> (let (
> (result (replace-regexp-in-string "\r?\n$" ""
> (shell-command-to-string (concat "grep "
> "2008-06-17"
> " ~/org/memacs/files.org_archive");; hard coded stuff for testing purposes
> )
> )
> )
> )
> (message (concat "result -> " result))
> (re-search-forward " \[\[.+\]\[" nil t 1)
> (let (
> (firstlink ((match-string 1)))
> )
> (message (concat "first link -> " firstlink))
> )
> )
> #+END_SRC
>
>
>
> [1] https://github.com/novoid/Memacs
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Fast Opening of Memacs Indexed Files (was: Elisp: help on string operations for fast file visiting)
2016-11-07 16:27 Elisp: help on string operations for fast file visiting Karl Voit
2016-11-08 8:42 ` Alan Schmitt
2016-12-21 0:30 ` John Kitchin
@ 2017-01-02 10:00 ` Karl Voit
2 siblings, 0 replies; 5+ messages in thread
From: Karl Voit @ 2017-01-02 10:00 UTC (permalink / raw)
To: emacs-orgmode
* Karl Voit <devnull@Karl-Voit.at> wrote:
> Hi!
>
> For Memacs[1], I'd like to come up with a very fast Org-mode method to
> open files independent of their location on your disk.
With the help of John Kitchin, I am now able to present you the
solution for the issue:
http://karl-voit.at/2017/01/01/memacs-grep/
In case you're using Memacs, this function might worth a look.
--
get mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML into Org-mode:
> get Memacs from https://github.com/novoid/Memacs <
Personal Information Management > http://karl-voit.at/tags/pim/
Emacs-related > http://karl-voit.at/tags/emacs/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-01-02 10:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-07 16:27 Elisp: help on string operations for fast file visiting Karl Voit
2016-11-08 8:42 ` Alan Schmitt
2016-11-08 9:28 ` Karl Voit
2016-12-21 0:30 ` John Kitchin
2017-01-02 10:00 ` Fast Opening of Memacs Indexed Files (was: Elisp: help on string operations for fast file visiting) Karl Voit
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).