From mboxrd@z Thu Jan 1 00:00:00 1970 From: eniotna Subject: Re: Add caching to org-buffer-property-keys Date: Tue, 12 Apr 2016 19:22:06 +0200 Message-ID: References: <2016-03-02T12-21-52@devnull.Karl-Voit.at> <56D73594.6090908@free.fr> <2016-04-12T15-52-23@devnull.Karl-Voit.at> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1134714c88c7bd05304ce62c Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aq20w-00023w-5b for emacs-orgmode@gnu.org; Tue, 12 Apr 2016 13:22:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aq20u-0007wv-EI for emacs-orgmode@gnu.org; Tue, 12 Apr 2016 13:22:10 -0400 Received: from mail-lf0-x229.google.com ([2a00:1450:4010:c07::229]:33851) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aq20u-0007we-0j for emacs-orgmode@gnu.org; Tue, 12 Apr 2016 13:22:08 -0400 Received: by mail-lf0-x229.google.com with SMTP id j11so34926272lfb.1 for ; Tue, 12 Apr 2016 10:22:07 -0700 (PDT) In-Reply-To: <2016-04-12T15-52-23@devnull.Karl-Voit.at> 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" To: Karl Voit Cc: Org Mode Mailing List --001a1134714c88c7bd05304ce62c Content-Type: text/plain; charset=UTF-8 Hello, > I'm sure, it's only a small error of mine. Replace `(mapcar #'list (org-entry-properties nil nil))` by `(org-entry-properties nil nil)` in your `org-read-entry-property-name` definition: ``` (defun org-read-entry-property-name () "Read a property name from the current entry (basically a rewrite of org-read-property-name which uses org-entry-properties instead to speed up)" (let ((completion-ignore-case t) (default-prop (or (and (org-at-property-p) (org-match-string-no-properties 2)) org-last-set-property))) (org-completing-read (concat "Property" (if default-prop (concat " [" default-prop "]") "") ": ") (org-entry-properties nil nil) nil nil nil nil default-prop))) ``` Regards, tony / @ardumont On Tue, Apr 12, 2016 at 3:55 PM, Karl Voit wrote: > * Thierry Banel wrote: > > Nice function! > > Maybe a rewrite of (org-read-property-name) calling > > (org-entry-properties) could speed up things. > > (org-entry-properties) returns an assoc list of the local header > properties. > > OK, great idea. > > I tried by myself (Elisp noob) and failed: see code below. > > The code evaluates without complaining but when I use the function, > I get asked for a property which gets also correctly written to the > property. However, the completion of the property does not work. > > I'm sure, it's only a small error of mine. > > Thanks for your help here! > > > ;; version that tries to read only properties of current entry: > (defun org-read-entry-property-name () > "Read a property name from the current entry (basically a rewrite of > org-read-property-name which uses org-entry-properties instead to speed > up)" > (let ((completion-ignore-case t) > (default-prop (or (and (org-at-property-p) > (org-match-string-no-properties 2)) > org-last-set-property))) > (org-completing-read > (concat "Property" > (if default-prop (concat " [" default-prop "]") "") > ": ") > ;; ORIGINAL LINE: (mapcar #'list (org-buffer-property-keys nil t t)) > (mapcar #'list (org-entry-properties nil nil)) > nil nil nil nil default-prop))) > > (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-entry-property-name)))) > ;; set property > (org-set-property prop val)))) > > > -- > 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 > > > --001a1134714c88c7bd05304ce62c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello,

> I'm sure, it's only a smal= l error of mine.

Replace `(mapcar #'list (org-entry-properties nil nil))` by `(org-e= ntry-properties nil nil)` in your `org-read-entry-property-name` definition= :

```
(defun org-read-entry-property-name ()
=C2=A0 "Read= a property name from the current entry (basically a rewrite of
=C2=A0= =C2=A0 org-read-property-name which uses org-entry-properties instead to sp= eed up)"
=C2=A0 (let ((completion-ignore-case t)
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 (default-prop (or (and (org-at-property-p)
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (org-match-string-no-properties 2))
=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 or= g-last-set-property)))
=C2=A0=C2=A0=C2=A0 (org-completing-read
=C2=A0= =C2=A0=C2=A0=C2=A0 (concat "Property"
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (if default-prop (concat &= quot; [" default-prop "]") "")
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ": ")=C2=A0=C2=A0=C2=A0=C2=A0 (org-entry-properties nil nil)
=C2=A0=C2=A0= =C2=A0=C2=A0 nil nil nil nil default-prop)))
```

Regards,

tony / @ardumont
<= /div>
On Tue, Apr 12, 2016 at 3:55 PM, Karl Voit <= span dir=3D"ltr"><devnull@karl-voit.at> wrote:
* Thierry Banel <tbanelwebmin@free.fr> wrote:
> Nice function!
> Maybe a rewrite of (org-read-property-name) calling
> (org-entry-properties) could speed up things.
> (org-entry-properties) returns an assoc list of the local header prope= rties.

OK, great idea.

I tried by myself (Elisp noob) and failed: see code below.

The code evaluates without complaining but when I use the function,
I get asked for a property which gets also correctly written to the
property. However, the completion of the property does not work.

I'm sure, it's only a small error of mine.

Thanks for your help here!


;; version that tries to read only properties of current entry:
(defun org-read-entry-property-name ()
=C2=A0 "Read a property name from the current entry (basically a rewri= te of
=C2=A0 =C2=A0org-read-property-name which uses org-entry-properties instead= to speed up)"
=C2=A0 (let ((completion-ignore-case t)
=C2=A0 =C2=A0 (default-prop (or (and (org-at-property-p)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-m= atch-string-no-properties 2))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 org-last-set-property))) =C2=A0 =C2=A0 (org-completing-read
=C2=A0 =C2=A0 =C2=A0(concat "Property"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if default-prop (concat " [" d= efault-prop "]") "")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0": ")
=C2=A0 =C2=A0 =C2=A0;; ORIGINAL LINE: (mapcar #'list (org-buffer-proper= ty-keys nil t t))
=C2=A0 =C2=A0 =C2=A0(mapcar #'list (org-entry-properties nil nil))
=C2=A0 =C2=A0 =C2=A0nil nil nil nil default-prop)))

(defun my-org-region-to-property (&optional property)
=C2=A0 (interactive)
=C2=A0 ;; if no region is defined, do nothing
=C2=A0 (if (use-region-p)
=C2=A0 =C2=A0 =C2=A0 ;; if a region string is found, ask for a property and= set property to
=C2=A0 =C2=A0 =C2=A0 ;; the string in the region
=C2=A0 =C2=A0 =C2=A0 (let ((val (replace-regexp-in-string
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\\`[ \= t\n]*" ""
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (replace-reg= exp-in-string "[ \t\n]*\\'" ""
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (substring (buffer-string)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(- (region-beginning) 1) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(region-end))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; if none was stated by user, re= ad property from user
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (prop (or property
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (org-read-entry-property-name))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; set property
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-set-property prop val))))


--
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
=C2=A0 =C2=A0 =C2=A0 =C2=A0> get Memacs from https://github.com/n= ovoid/Memacs <

https://github.com/novoid/extract_pdf_an= notations_to_orgmode + more on github



--001a1134714c88c7bd05304ce62c--