From mboxrd@z Thu Jan 1 00:00:00 1970 From: Karl Voit 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 Message-ID: <2015-05-28T15-53-04@devnull.Karl-Voit.at> References: <2015-05-28T12-10-26@devnull.Karl-Voit.at> Reply-To: Karl Voit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxyMm-0002d7-69 for emacs-orgmode@gnu.org; Thu, 28 May 2015 10:01:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxyMg-00020m-5U for emacs-orgmode@gnu.org; Thu, 28 May 2015 10:01:00 -0400 Received: from plane.gmane.org ([80.91.229.3]:35410) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxyMf-00020f-RL for emacs-orgmode@gnu.org; Thu, 28 May 2015 10:00:54 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YxyMe-0005El-7f for emacs-orgmode@gnu.org; Thu, 28 May 2015 16:00:52 +0200 Received: from friends.grml.info ([136.243.234.19]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 28 May 2015 16:00:52 +0200 Received: from news1142 by friends.grml.info with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 28 May 2015 16:00:52 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org * Karl Voit 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