emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Easy to use asking for Or-gmode property values (e.g., for Org-contacts)
@ 2015-05-28 10:11 Karl Voit
  2015-05-28 14:00 ` Karl Voit
  0 siblings, 1 reply; 2+ messages in thread
From: Karl Voit @ 2015-05-28 10:11 UTC (permalink / raw)
  To: emacs-orgmode

Hi!

I am using Org-contacts that way, that I copy new information from
external sources and move them to the properties afterwards:

: ** Firstname Lastname                      :FirstnameLastname:
: :PROPERTIES:
: :TYPE:
: :TITLE:
: :EMAIL: Firstname@company.com
: :URL:
: :MOBILE: 0043/
: :HOMEPHONE:
: :WORKPHONE:
: :PHONE:
: :COMPANY: This Company
: :STREET: Companystreet 42
: :POSTALCODE: 8010
: :CITY: Thiscity
: :COUNTRY: Österreich
: :PHOTOGRAPH: [[photo:FirstnameLastname.jpg]]
: :BORN: 1970-12-31
: :ITOLDTHEM_EMAIL: thisorthat@mydomain.com
: :ITOLDTHEM_ADDRESS:
: :ITOLDTHEM_PHONE:
: :ADDRESS_CHANGE_METHOD: email
: :CREATED:  [2015-05-27 Wed 19:46]
: :END:
:
: - <2013-01-13 Fri> met at dinner party
:   - This old company
:   - Firstname@oldcompany.com
: - <2015-05-27 Wed> contact from XING with new data
:   - This Company
:   - Firstname@company.com
:   - Companystreet 42, 8010 Thiscity
:   - he is born on December 31st, 1970

This way, I do have the whole history below the properties and the
most current information.

The task of adding information is tedious: copy & paste from external
sources and then copy & paste to the properties accordingly.

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

The workflow would improve a lot! And I do guess that this might be a
very handy function for lots of other purposes as well: ask me for all
or some properties!

With my very limited understanding of elisp: can this (easily) done?

Is there a code snippet which does similar stuff?

-- 
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] 2+ messages in thread

* Re: Easy to use asking for Or-gmode property values (e.g., for Org-contacts)
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Karl Voit @ 2015-05-28 14:00 UTC (permalink / raw)
  To: emacs-orgmode

* 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-28 14:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

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).