From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: two basic elisp questions Date: Fri, 22 Jul 2016 22:27:06 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=94eb2c1902fe96110b053844490a Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQmek-0001Id-B0 for emacs-orgmode@gnu.org; Fri, 22 Jul 2016 22:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQmeh-000821-Sl for emacs-orgmode@gnu.org; Fri, 22 Jul 2016 22:27:09 -0400 Received: from mail-qt0-x22b.google.com ([2607:f8b0:400d:c0d::22b]:35200) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQmeh-00081x-M3 for emacs-orgmode@gnu.org; Fri, 22 Jul 2016 22:27:07 -0400 Received: by mail-qt0-x22b.google.com with SMTP id x25so71526740qtx.2 for ; Fri, 22 Jul 2016 19:27:07 -0700 (PDT) In-Reply-To: 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: Org Mode --94eb2c1902fe96110b053844490a Content-Type: text/plain; charset=UTF-8 On Fri, Jul 22, 2016 at 1:54 PM, Michael Welle wrote: > Hello, > > Matt Price writes: > > > On Fri, Jul 22, 2016 at 11:38 AM, Matt Price wrote: > > > >> > >> (2) Is it possible to set the default value for interactive file > selection > >> to something OTHER than the currect directory of the current buffer? > >> Something like: > >> > >> (let > >> ((base-dir "./Assignment1/")) > >> (org-attach--attach)) > >> > >> I'd like to set different base directories when attaching files to > >> subtrees of different first-level trees in a buffer. I guess I would set > >> the value for the base directory with a property. > >> > > > > OK, I made some progress on this: > > > > (let ((default-directory (concat default-directory "Assignment1/") )) > > (call-interactively 'org-attach-attach)) > > > > However, I'd like to do something like: > > > > (let > > ((parent-basedir nil)) > > (save-excursion > > (outline-up-heading) > > (setq parent-basedir (org-get-entry "BASEDIR"))) > > (let > > ((default-directory (concat default-directory parent-basedir) )) > > (call-interactively 'org-attach-attach ))) > > > > > > > > But there are errors I don't understand in this code. Any hints? Thanks > > again! > well, I guess the errors are too secret to share them with us? The first > I can see is that org-get-entry doesn't need parameters. And the overall > structure looks strange, but that could be just me ;). > > :-( No, they're not too secret, I just have a terrible head cold and can hardly think, so didn't think to include it! The overall structure feels strange to me -- I just want a way of retaining a temprary variable value in a let that also includes a temporary excursion to the parent node. More on that shortly. > The reason for the current behaviour is the interactive form of > org-attach-attach. Ad hoc I have no idea how to change that. What I > would try is to (cd your-wanted-dir) before calling org-attach-attach. > Maybe a bit of cleanup if useful after calling the function. > So it turns out that, like most interactive functions, org-attach-attach uses the built-in read-file-name macro, which relies on the value of "default-directory", which is buffer-local. By calling org-attach-attach from inside a let statement, I can get the behaviour I want: (let ((default-directory (concat default-directory "Galileo/"))) (org-attach-attach)) The problem now is that I need to access a property from the parent node in order ot dynamically set the appropriate value for default-directory, and I'm struggling to do that. Here is a minimal test file: * Galileo :ASSIGNMENT: :PROPERTIES: :BASEDIR: Galileo :END: ** testing #+BEGIN_SRC emacs-lisp (let ((parent-basedir nil)) (save-excursion (outline-up-heading) (setq parent-basedir (org-entry-get (point) "BASEDIR")) (message parent-basedir)) (let ((default-directory (concat default-directory parent-basedir) )) (call-interactively 'org-attach-attach ))) #+END_SRC This seems to work but so far I'm having issues actually opening the attachment. This may be due to the way that org-attach constructs links to attachments (I prefer not to copy, as my disk space is limited). Anyway, thanks for your help; this seems to be getting closer, despite what feels like substantial mental impairment due to increased cranial pressure (ouch!) Matt > Regards > hmw > > > --94eb2c1902fe96110b053844490a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Fri, Jul 22, 2016 at 1:54 PM, Michael Welle <mwe012008@gmx.net&= gt; wrote:
Hello,

Matt Price <moptop99@gmail.com= > writes:

> On Fri, Jul 22, 2016 at 11:38 AM, Matt P= rice <moptop99@gmail.com> w= rote:
>
>>
>> (2) Is it possible to set the default value for interactive file s= election
>> to something OTHER than the currect directory of the current buffe= r?
>> Something like:
>>
>> (let
>>=C2=A0 =C2=A0((base-dir "./Assignment1/"))
>>=C2=A0 =C2=A0(org-attach--attach))
>>
>> I'd like to set different base directories when attaching file= s to
>> subtrees of different first-level trees in a buffer. I guess I wou= ld set
>> the value for the base directory with a property.
>>
>
> OK, I made some progress on this:
>
> (let ((default-directory=C2=A0 (concat default-directory "Assignm= ent1/") ))
> (call-interactively 'org-attach-attach))
>
> However, I'd like to do something like:
>
> (let
>=C2=A0 =C2=A0 =C2=A0((parent-basedir nil))
>=C2=A0 =C2=A0(save-excursion
>=C2=A0 =C2=A0 =C2=A0(outline-up-heading)
>=C2=A0 =C2=A0 =C2=A0(setq parent-basedir (org-get-entry "BASEDIR&q= uot;)))
>=C2=A0 =C2=A0(let
>=C2=A0 =C2=A0 =C2=A0 =C2=A0((default-directory (concat default-director= y parent-basedir) ))
>=C2=A0 =C2=A0 =C2=A0(call-interactively 'org-attach-attach=C2=A0 ))= )
>
>
>
> But there are errors I don't understand in this code. Any hints? T= hanks
> again!
well, I guess the errors are too secret to share them with us? = The first
I can see is that org-get-entry doesn't need parameters. And the overal= l
structure looks strange, but that could be just me ;).

:-( No, they're not too secret, I just have a ter= rible head cold and can hardly think, so didn't think to include it!
The overall structure feels strange to me -- I just want a = way of retaining a temprary variable value in a let that also includes a te= mporary excursion to the parent node. More on that shortly.
= =C2=A0
The reason for the current behaviour is the interactive form of
org-attach-attach. Ad hoc I have no idea how to change that. What I
would try is to (cd your-wanted-dir) before calling org-attach-attach.
Maybe a bit of cleanup if useful after calling the function.

So it turns out=C2=A0 that, like most interactive fun= ctions, org-attach-attach uses the built-in read-file-name macro, which rel= ies on the value of "default-directory", which is buffer-local. B= y calling org-attach-attach from inside a let statement, I can get the beha= viour I want:
(let
=C2=A0 ((default-directory = (concat default-directory "Galileo/")))
=C2=A0 (org= -attach-attach))


=C2=A0The problem now is that I need= to access a property from the parent node in order ot dynamically set the = appropriate value for default-directory, and I'm struggling to do that.=

Here is a minimal test file:

* Galileo :ASSIGNMEN= T:
:PROPERTIES:
:BASEDIR:=C2=A0 Galileo
:END:


** testin= g
#+BEGIN_SRC emacs-lisp
=C2=A0 (let
=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 ((parent-basedir nil))
=C2=A0=C2=A0=C2=A0 (save-excursion
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (outline-up-heading)
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (setq parent-basedir (org-entry-get (point) "BASEDIR"))=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (message parent-basedir))
=C2=A0=C2=A0= =C2=A0 (let
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((default-directo= ry (concat default-directory parent-basedir) ))
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (call-interactively 'org-attach-attach=C2=A0 )))
#+END_SRC
This seems to work but so far I'm having issues actuall= y opening the attachment.=C2=A0 This may be due to the way that org-attach = constructs links to attachments (I prefer not to copy, as my disk space is = limited).
Anyway, thanks for your help; this seems to be gett= ing closer, despite what feels like substantial mental impairment due to in= creased cranial pressure (ouch!)
Matt


Regards
hmw



--94eb2c1902fe96110b053844490a--