emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* two basic elisp questions
@ 2016-07-22 15:38 Matt Price
  2016-07-22 16:13 ` Matt Price
  2016-07-22 17:27 ` Michael Welle
  0 siblings, 2 replies; 7+ messages in thread
From: Matt Price @ 2016-07-22 15:38 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 742 bytes --]

(1) can I interactively call an e lisp function like "org-set-property" and
provide a single argument to it even if it expects 2, e.g.:
(call-interactively 'org-set-protertyt (vector "GRADE" ))? (I don't seem to
be able to pass ANY arguments via call-interactively so maybe I
misunderstand something fundamental).

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

thanks!
Matt

[-- Attachment #2: Type: text/html, Size: 938 bytes --]

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

* Re: two basic elisp questions
  2016-07-22 15:38 two basic elisp questions Matt Price
@ 2016-07-22 16:13 ` Matt Price
  2016-07-22 17:54   ` Michael Welle
  2016-07-22 17:27 ` Michael Welle
  1 sibling, 1 reply; 7+ messages in thread
From: Matt Price @ 2016-07-22 16:13 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1037 bytes --]

On Fri, Jul 22, 2016 at 11:38 AM, Matt Price <moptop99@gmail.com> 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!

[-- Attachment #2: Type: text/html, Size: 1620 bytes --]

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

* Re: two basic elisp questions
  2016-07-22 15:38 two basic elisp questions Matt Price
  2016-07-22 16:13 ` Matt Price
@ 2016-07-22 17:27 ` Michael Welle
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Welle @ 2016-07-22 17:27 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Matt Price <moptop99@gmail.com> writes:

> (1) can I interactively call an e lisp function like "org-set-property" and
> provide a single argument to it even if it expects 2, e.g.:
> (call-interactively 'org-set-protertyt (vector "GRADE" ))? (I don't seem to
> be able to pass ANY arguments via call-interactively so maybe I
> misunderstand something fundamental).
right, call-interactively uses the interactive form of the called
function to figure out the parameters and their values. Maybe you are
looking for something like this:


(defun set-foo-value (value)
  (interactive
   (list (read-string "prop value: " nil nil "<empty>")))
  (org-set-property "foo" value))

(call-interactively 'set-foo-value)

Regards
hmw

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

* Re: two basic elisp questions
  2016-07-22 16:13 ` Matt Price
@ 2016-07-22 17:54   ` Michael Welle
  2016-07-23  2:27     ` Matt Price
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Welle @ 2016-07-22 17:54 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Matt Price <moptop99@gmail.com> writes:

> On Fri, Jul 22, 2016 at 11:38 AM, Matt Price <moptop99@gmail.com> 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 ;).

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.

Regards
hmw

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

* Re: two basic elisp questions
  2016-07-22 17:54   ` Michael Welle
@ 2016-07-23  2:27     ` Matt Price
  2016-07-23  5:24       ` Michael Welle
  0 siblings, 1 reply; 7+ messages in thread
From: Matt Price @ 2016-07-23  2:27 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 3486 bytes --]

On Fri, Jul 22, 2016 at 1:54 PM, Michael Welle <mwe012008@gmx.net> wrote:

> Hello,
>
> Matt Price <moptop99@gmail.com> writes:
>
> > On Fri, Jul 22, 2016 at 11:38 AM, Matt Price <moptop99@gmail.com> 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
>
>
>

[-- Attachment #2: Type: text/html, Size: 4965 bytes --]

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

* Re: two basic elisp questions
  2016-07-23  2:27     ` Matt Price
@ 2016-07-23  5:24       ` Michael Welle
  2016-07-29 14:15         ` Matt Price
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Welle @ 2016-07-23  5:24 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Matt Price <moptop99@gmail.com> writes:

> On Fri, Jul 22, 2016 at 1:54 PM, Michael Welle <mwe012008@gmx.net> wrote:
>
>> Hello,
>>
>> Matt Price <moptop99@gmail.com> writes:
>>
>> > On Fri, Jul 22, 2016 at 11:38 AM, Matt Price <moptop99@gmail.com> 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!
don't worry and get well soon ;).


> 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))
That makes sense.


>  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
I use Emacs 25 and there outline-up-heading uses a mandatory
parameter. I changed that to (outline-up-heading 1).


> 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).
I haven't used attachments before, so I'm not sure what to expect. But if
I use the code from above, I get the attachment related properties, as you
said. Next I do M-x org-attach o and I get prompted for the attachment,
which isn't right I think. The reason is IMO, that org-attach-open
searches the attachment below the default-directory, not in the changed
path. So, if the default-directory is /tmp, it searches /tmp/data/$ID,
not /tmp/Galileo/date/$ID. Thinking about it that makes sense, somehow ;).

So it looks like the are several more places where 'cheating' is needed
to make this work.


> Anyway, thanks for your help; this seems to be getting closer, despite what
> feels like substantial mental impairment due to increased cranial pressure
> (ouch!)
I can feel your pain. Last week I had something that could have been an
inflammation of the middle ear or something like that. For two nights it
felt like my ear and the associated part of the head will explode. One
don't need that too often ;).

Regards
hmw

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

* Re: two basic elisp questions
  2016-07-23  5:24       ` Michael Welle
@ 2016-07-29 14:15         ` Matt Price
  0 siblings, 0 replies; 7+ messages in thread
From: Matt Price @ 2016-07-29 14:15 UTC (permalink / raw)
  Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 5273 bytes --]

On Sat, Jul 23, 2016 at 1:24 AM, Michael Welle <mwe012008@gmx.net> wrote:

> Hello,
>
> Matt Price <moptop99@gmail.com> writes:
>
> > On Fri, Jul 22, 2016 at 1:54 PM, Michael Welle <mwe012008@gmx.net>
> wrote:
> >
> >> Hello,
> >>
> >> Matt Price <moptop99@gmail.com> writes:
> >>
> >> > On Fri, Jul 22, 2016 at 11:38 AM, Matt Price <moptop99@gmail.com>
> 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!
> don't worry and get well soon ;).
>
>
> > 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))
> That makes sense.
>
>
> >  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
> I use Emacs 25 and there outline-up-heading uses a mandatory
> parameter. I changed that to (outline-up-heading 1).
>
>
> > 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).
> I haven't used attachments before, so I'm not sure what to expect. But if
> I use the code from above, I get the attachment related properties, as you
> said. Next I do M-x org-attach o and I get prompted for the attachment,
> which isn't right I think. The reason is IMO, that org-attach-open
> searches the attachment below the default-directory, not in the changed
> path. So, if the default-directory is /tmp, it searches /tmp/data/$ID,
> not /tmp/Galileo/date/$ID. Thinking about it that makes sense, somehow ;).
>
> So it looks like the are several more places where 'cheating' is needed
> to make this work.
>
Yes. Looks like I wold need to rewrite org-attach-attach and bind to my new
function; that feels hard so I've sort of given up on it for now.

>
>
> > Anyway, thanks for your help; this seems to be getting closer, despite
> what
> > feels like substantial mental impairment due to increased cranial
> pressure
> > (ouch!)
> I can feel your pain. Last week I had something that could have been an
> inflammation of the middle ear or something like that. For two nights it
> felt like my ear and the associated part of the head will explode. One
> don't need that too often ;).
>
> FINALLY getting better! thank you!
sorry ofr the longdelay. If I don get around to rewriting org-attach-attach
I'll report back.

[-- Attachment #2: Type: text/html, Size: 7264 bytes --]

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

end of thread, other threads:[~2016-07-29 14:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-22 15:38 two basic elisp questions Matt Price
2016-07-22 16:13 ` Matt Price
2016-07-22 17:54   ` Michael Welle
2016-07-23  2:27     ` Matt Price
2016-07-23  5:24       ` Michael Welle
2016-07-29 14:15         ` Matt Price
2016-07-22 17:27 ` Michael Welle

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