[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Easy to use asking for Or-gmode property values (e.g., for Org-c
From: |
Karl Voit |
Subject: |
Re: [O] Easy to use asking for Or-gmode property values (e.g., for Org-contacts) |
Date: |
Thu, 28 May 2015 16:00:07 +0200 |
User-agent: |
slrn/pre1.0.0-18 (Linux) |
* Karl Voit <address@hidden> wrote:
>
> This is why I came up with this idea: how about I paste new
> information at the end of and then call a function which helps me a
> lot:
>
> - ask for each property (or a set of pre-defined properties)
> - prompt property name
> - let the user mark a region using keyboard or mouse
> - if user presses confirmation keyoard shortcut (return?)
> - if region: copy the region and set it as the new content for the current
> property (overwriting any old property settings)
> - if no region is set: do not change property
Jonathan Leech-Pepin sent me his solution to the issue. Instead of
asking for a set of properties, he wrote a function that takes the
currently selected region, asks for a property, and overwrites its
value with the region string.
I found an edge-case which I fixed (by removing leading and trailing
whitespaces) and I added comments as far as I understood the code.
The resulting function is:
,----
| (defun my-org-region-to-property (&optional property)
| (interactive)
| ;; if no region is defined, do nothing
| (if (use-region-p)
| ;; if a region string is found, ask for a property and set property to
| ;; the string in the region
| (let ((val (replace-regexp-in-string
| "\\`[ \t\n]*" ""
| (replace-regexp-in-string "[ \t\n]*\\'" ""
| (substring (buffer-string)
| (- (region-beginning)
1)
| (region-end))))
| )
| ;; if none was stated by user, read property from user
| (prop (or property
| (org-read-property-name))))
| ;; set property
| (org-set-property prop val))))
`----
Thank you very much, Jonathan!
The only downside of this method is, that I have to wait four
seconds until Org-mode has parsed the list of possible properties
within my contacts.org file.
Is there some kind of caching I could activate similar to (setq
org-refile-use-cache t)?
--
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