emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Karl Voit <devnull@Karl-Voit.at>
To: emacs-orgmode@gnu.org
Subject: Re: Easy to use asking for Or-gmode property values (e.g., for Org-contacts)
Date: Thu, 28 May 2015 16:00:07 +0200	[thread overview]
Message-ID: <2015-05-28T15-53-04@devnull.Karl-Voit.at> (raw)
In-Reply-To: 2015-05-28T12-10-26@devnull.Karl-Voit.at

* Karl Voit <devnull@Karl-Voit.at> 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

      reply	other threads:[~2015-05-28 14:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-28 10:11 Easy to use asking for Or-gmode property values (e.g., for Org-contacts) Karl Voit
2015-05-28 14:00 ` Karl Voit [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2015-05-28T15-53-04@devnull.Karl-Voit.at \
    --to=devnull@karl-voit.at \
    --cc=emacs-orgmode@gnu.org \
    --cc=news1142@Karl-Voit.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).