Re: [O] org-map-entries but with arguments?

2019-09-18 Thread John Kitchin
You can get an alist of all the properties in an entry with
org-entry-properties, and then you can let-alist these, or do something
else. Here is an example that might be related.

* test
  :PROPERTIES:
  :some-random-property: True
  :END:

#+BEGIN_SRC emacs-lisp :results code
(org-entry-properties)
#+END_SRC

#+RESULTS:
#+begin_src emacs-lisp
(("CATEGORY" . "2019-09-18 21:33")
 ("SOME-RANDOM-PROPERTY" . "True")
 ("BLOCKED" . "")
 ("FILE" . "/Users/jkitchin/Box
Sync/kitchingroup/jkitchin/journal/2019/09/18 21:33/2019-09-18 21:33.org")
 ("PRIORITY" . "B")
 ("ITEM" . "test"))
#+end_src

#+BEGIN_SRC emacs-lisp
(let-alist (cl-loop for (key . value) in (org-entry-properties)
   collect (cons (intern key) value))
 .SOME-RANDOM-PROPERTY)
#+END_SRC

#+RESULTS:
: True

John

---
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Wed, Sep 18, 2019 at 9:11 PM Matt Price  wrote:

>
> Sorry, replied to Adam directly by accident.
>
> On Wed, Sep 18, 2019 at 8:32 PM Matt Price  wrote:
>
>>
>>
>> On Wed, Sep 18, 2019 at 5:31 PM Adam Porter  wrote:
>>
>>> Matt Price  writes:
>>>
>>> > Is there a lisp trick for adding arguments to the function called by
>>> > `org-map-entries`?
>>> >
>>> > I have the following function:
>>> >
>>> > (cl-defun org-lms-return-all-assignments ( (send-all nil)
>>> (also-mail nil) (post-to-lms t) )
>>> >   "By default mail all subtrees 'READY' to student recipients, unless
>>> SEND-ALL is non-nil.
>>> > In that case, send all marked 'READY' or 'TODO'."
>>> >   (interactive)
>>> >   (message "Mailing all READY subtrees to students")
>>> >   (let ((send-condition
>>> >  (if send-all
>>> >  `(or (string= (org-element-property :todo-keyword item)
>>> "READY")
>>> >   (string= (org-element-property :todo-keyword item)
>>> "TODO") )
>>> >`(string= (org-element-property :todo-keyword item) "READY")
>>> >)))
>>> > (org-map-entries
>>> >  #'ol-send-just-one))
>>> >   (org-cycle-hide-drawers 'all))
>>> >
>>> > I'd like to relay some of hte functions arguments to the one called
>>> > internally to do the work.  ~(ol-send-just-one~ takes an ~also-mail~
>>> > and a ~post-to-lms~ parameter,just like
>>> > ~org-lms-return-all-assignments~, but I'm not sure how to trick
>>> > org-map-entries into passing those arguments on. Any hints?  Thank
>>> > you!
>>>
>>> Hi Matt,
>>>
>>> If I may, I think org-ql can help you here.  It should also work much
>>> faster than org-map-entries, because it can skip to entries with the
>>> desired to-do keywords (although you could also use the MATCH argument
>>> to org-map-entries to improve its speed).  Try this function (untested):
>>>
>>> #+BEGIN_SRC elisp
>>> (cl-defun org-lms-return-all-assignments-ql ( (send-all nil)
>>> (also-mail nil) (post-to-lms t))
>>>   "By default mail all subtrees 'READY' to student recipients, unless
>>> SEND-ALL is non-nil.
>>> In that case, send all marked 'READY' or 'TODO'."
>>>   (interactive)
>>>   (message "Mailing all READY subtrees to students")
>>>   (let ((todo-keywords (if send-all
>>>'("READY" "TODO")
>>>  '("READY"
>>> (org-ql-select (current-buffer)
>>>   `(todo ,@todo-keywords)
>>>   :action `(ol-send-just-one ,also-mail ,post-to-lms
>>> #+END_SRC
>>>
>>> OK, this is pretty cool, thank you.  I took John's excellent suggestion
>> of using a headline property to store the appropriate actions, but it makes
>> sense to switch to org-ql if I can master the syntax (which seems awfully
>> powerful).  One questions: does org-ql-select respect buffer narrowing?
>> That would be important for me.
>>
>> Man, hard to hold all this stuff in my head.  ANd very hard to navigate
>> my own code now that I see how ugly it is.
>>
>
> Another question.  In place of a function or sexp,  the :action key
> accepts the keyword "element" as a value, and will return a parsed
> headline. Is it possible to then pass that value on to a function that will
> be evaluated? I'm asking because I have a bunch of functions with very long
> `let` sections in which information is extracted from a headline with
> (org-entry-get). It would be nice to use John's plist trick (from the other
> thread we're on) to, essentially, let-plist all the properties of the
> headline. It would declutter my code significantly.
>


Re: [O] org-map-entries but with arguments?

2019-09-18 Thread Adam Porter
Matt Price  writes:

>  OK, this is pretty cool, thank you.  I took John's excellent
>  suggestion of using a headline property to store the appropriate
>  actions, but it makes sense to switch to org-ql if I can master the
>  syntax (which seems awfully powerful).  One questions: does
>  org-ql-select respect buffer narrowing? That would be important for
>  me.

Yes, just pass the argument ":narrow t".  Take a look at the examples
and documentation, you can do a bunch of things.  :)

> Another question.  In place of a function or sexp, the :action key
> accepts the keyword "element" as a value, and will return a parsed
> headline. Is it possible to then pass that value on to a function that
> will be evaluated? I'm asking because I have a bunch of functions with
> very long `let` sections in which information is extracted from a
> headline with (org-entry-get).

There are a few ways to do something like that:

1.  Just call functions like org-entry-get from the action function
(which is called with point at each match).  For simple things, this is
the simplest way.

2.  In a custom action function, do what the "element" action does, i.e.
(org-element-headline-parser (line-end-position)), then do whatever you
need with the resulting element.

3.  Collect the elements into a list (i.e. use ":action 'element") and
map across it.  Since that requires more consing, it will probably be
slower, but likely not a performance problem in most cases.

> It would be nice to use John's plist trick (from the other thread
> we're on) to, essentially, let-plist all the properties of the
> headline. It would declutter my code significantly.

You'll probably want to use -let from dash.el, with its  or 
destructuring.   was added to -let since John wrote that article,
and it also gives you all the other powerful features of -let.  It works
well and is fast.  You could also use pcase-let*'s destructuring, which
is built-in to Emacs, but its syntax is a bit more complex.




Re: [O] org-map-entries but with arguments?

2019-09-18 Thread Matt Price
Sorry, replied to Adam directly by accident.

On Wed, Sep 18, 2019 at 8:32 PM Matt Price  wrote:

>
>
> On Wed, Sep 18, 2019 at 5:31 PM Adam Porter  wrote:
>
>> Matt Price  writes:
>>
>> > Is there a lisp trick for adding arguments to the function called by
>> > `org-map-entries`?
>> >
>> > I have the following function:
>> >
>> > (cl-defun org-lms-return-all-assignments ( (send-all nil)
>> (also-mail nil) (post-to-lms t) )
>> >   "By default mail all subtrees 'READY' to student recipients, unless
>> SEND-ALL is non-nil.
>> > In that case, send all marked 'READY' or 'TODO'."
>> >   (interactive)
>> >   (message "Mailing all READY subtrees to students")
>> >   (let ((send-condition
>> >  (if send-all
>> >  `(or (string= (org-element-property :todo-keyword item)
>> "READY")
>> >   (string= (org-element-property :todo-keyword item)
>> "TODO") )
>> >`(string= (org-element-property :todo-keyword item) "READY")
>> >)))
>> > (org-map-entries
>> >  #'ol-send-just-one))
>> >   (org-cycle-hide-drawers 'all))
>> >
>> > I'd like to relay some of hte functions arguments to the one called
>> > internally to do the work.  ~(ol-send-just-one~ takes an ~also-mail~
>> > and a ~post-to-lms~ parameter,just like
>> > ~org-lms-return-all-assignments~, but I'm not sure how to trick
>> > org-map-entries into passing those arguments on. Any hints?  Thank
>> > you!
>>
>> Hi Matt,
>>
>> If I may, I think org-ql can help you here.  It should also work much
>> faster than org-map-entries, because it can skip to entries with the
>> desired to-do keywords (although you could also use the MATCH argument
>> to org-map-entries to improve its speed).  Try this function (untested):
>>
>> #+BEGIN_SRC elisp
>> (cl-defun org-lms-return-all-assignments-ql ( (send-all nil)
>> (also-mail nil) (post-to-lms t))
>>   "By default mail all subtrees 'READY' to student recipients, unless
>> SEND-ALL is non-nil.
>> In that case, send all marked 'READY' or 'TODO'."
>>   (interactive)
>>   (message "Mailing all READY subtrees to students")
>>   (let ((todo-keywords (if send-all
>>'("READY" "TODO")
>>  '("READY"
>> (org-ql-select (current-buffer)
>>   `(todo ,@todo-keywords)
>>   :action `(ol-send-just-one ,also-mail ,post-to-lms
>> #+END_SRC
>>
>> OK, this is pretty cool, thank you.  I took John's excellent suggestion
> of using a headline property to store the appropriate actions, but it makes
> sense to switch to org-ql if I can master the syntax (which seems awfully
> powerful).  One questions: does org-ql-select respect buffer narrowing?
> That would be important for me.
>
> Man, hard to hold all this stuff in my head.  ANd very hard to navigate my
> own code now that I see how ugly it is.
>

Another question.  In place of a function or sexp,  the :action key accepts
the keyword "element" as a value, and will return a parsed headline. Is it
possible to then pass that value on to a function that will be evaluated?
I'm asking because I have a bunch of functions with very long `let`
sections in which information is extracted from a headline with
(org-entry-get). It would be nice to use John's plist trick (from the other
thread we're on) to, essentially, let-plist all the properties of the
headline. It would declutter my code significantly.


Re: [O] lisp: scoping vars in repetitive defuns

2019-09-18 Thread Adam Porter
John Kitchin  writes:

> I am not sure why you have to loop over everything in a let statement
> though. you can use something like
> https://github.com/nicferrier/emacs-kv to get all the keys an loop
> over those to do what you want, or you can just use cl-loop to do
> that.

Recent Emacs versions also have, e.g. map-keys from map.el.




Re: [O] org-map-entries but with arguments?

2019-09-18 Thread John Kitchin
I guess this information should be accessible in the entry where the
function is called, e.g. by a property (that may be inherited or set in the
file). then in your function just get the property values and do what you
want. Alternatively, you can probably do this with global (or maybe
lexically let) variables.

John

---
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Wed, Sep 18, 2019 at 2:52 PM Matt Price  wrote:

> Is there a lisp trick for adding arguments to the function called by
> `org-map-entries`?
>
> I have the following function:
>
> (cl-defun org-lms-return-all-assignments ( (send-all nil)
> (also-mail nil) (post-to-lms t) )
>   "By default mail all subtrees 'READY' to student recipients, unless
> SEND-ALL is non-nil.
> In that case, send all marked 'READY' or 'TODO'."
>   (interactive)
>   (message "Mailing all READY subtrees to students")
>   (let ((send-condition
>  (if send-all
>  `(or (string= (org-element-property :todo-keyword item)
> "READY")
>   (string= (org-element-property :todo-keyword item)
> "TODO") )
>`(string= (org-element-property :todo-keyword item) "READY")
>)))
> (org-map-entries
>  #'ol-send-just-one))
>   (org-cycle-hide-drawers 'all))
>
> I'd like to relay some of hte functions arguments to the one called
> internally to do the work.  ~(ol-send-just-one~ takes an ~also-mail~ and a
> ~post-to-lms~ parameter,just like ~org-lms-return-all-assignments~, but I'm
> not sure how to trick org-map-entries into passing those arguments on. Any
> hints?  Thank you!
>
>


Re: [O] lisp: scoping vars in repetitive defuns

2019-09-18 Thread John Kitchin
I played with a similar idea of converting a plist to something you can
call to access values at
https://kitchingroup.cheme.cmu.edu/blog/2017/04/16/A-callable-plist-data-structure-for-Emacs/.
It did end up as a macro, but no eval required. It never made it past that
post, but it might have an application here.

I am not sure why you have to loop over everything in a let statement
though. you can use something like https://github.com/nicferrier/emacs-kv to
get all the keys an loop over those to do what you want, or you can just
use cl-loop to do that. So, unless you are defining new variables for
readability you shouldn't need to let bind anything that is in the plist,
only new things that are derived from it.

John

---
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Wed, Sep 18, 2019 at 5:45 PM Adam Porter  wrote:

> Joost Kremers  writes:
>
> > On Wed, Sep 18 2019, Matt Price wrote:
> >> Is thre away to do that kind of destructuring bind -- which
> >> binds *everything* in the plist, without knowing the symbol names in
> >> advance? that would be really great.
> >
> > let-alist perhaps?
>
> Well, let-alist is for alists, not plists.  ;) But anyway, it's a macro,
> and it does require knowing keys at compile time.  -let is a good
> alternative for plists and other maps.
>
>
>


Re: [O] lisp: scoping vars in repetitive defuns

2019-09-18 Thread Adam Porter
Joost Kremers  writes:

> On Wed, Sep 18 2019, Matt Price wrote:
>> Is thre away to do that kind of destructuring bind -- which
>> binds *everything* in the plist, without knowing the symbol names in
>> advance? that would be really great.
>
> let-alist perhaps?

Well, let-alist is for alists, not plists.  ;) But anyway, it's a macro,
and it does require knowing keys at compile time.  -let is a good
alternative for plists and other maps.




Re: [O] lisp: scoping vars in repetitive defuns

2019-09-18 Thread Adam Porter
Matt Price  writes:

> This is fun, thanks John. I really like the plist version put would
> also like to loop through the variables in a let statement somehow.
>
> I think what I'm missing is the equivalent of a javascript implicit
> destructuring construct:
>
> let { } = object;
>
> which will define new variables prop1, prop2... forever enumerable
> property of the object.  Is thre away to do that kind of destructuring
> bind -- which binds *everything* in the plist, without knowing the
> symbol names in advance? that would be really great.

In fact, he has written an article about that sort of thing, which you
can find linked here, along with some other destructuring tools:

https://github.com/alphapapa/emacs-package-dev-handbook#a-callable-plist-data-structure-for-emacs
https://github.com/alphapapa/emacs-package-dev-handbook#with-dict-with-plist-vals-1

Note that automatically binding variables named according to plist keys
which are not known in advance would have to happen at runtime and would
require use of eval, as well as potentially overriding variables that
you're already using.

Instead, I recommend using -let, which has a  keyword, which you
can use like:

  (-let* ((( :query :preamble :preamble-case-fold) 
(org-ql--query-preamble query)))
(list query preamble preamble-case-fold))




Re: [O] org-map-entries but with arguments?

2019-09-18 Thread Adam Porter
Matt Price  writes:

> Is there a lisp trick for adding arguments to the function called by
> `org-map-entries`?
>
> I have the following function:
>
> (cl-defun org-lms-return-all-assignments ( (send-all nil) (also-mail 
> nil) (post-to-lms t) )
>   "By default mail all subtrees 'READY' to student recipients, unless 
> SEND-ALL is non-nil.
> In that case, send all marked 'READY' or 'TODO'."
>   (interactive)
>   (message "Mailing all READY subtrees to students")
>   (let ((send-condition
>  (if send-all
>  `(or (string= (org-element-property :todo-keyword item) "READY")
>   (string= (org-element-property :todo-keyword item) "TODO") )
>`(string= (org-element-property :todo-keyword item) "READY")
>)))
> (org-map-entries 
>  #'ol-send-just-one))
>   (org-cycle-hide-drawers 'all))
>
> I'd like to relay some of hte functions arguments to the one called
> internally to do the work.  ~(ol-send-just-one~ takes an ~also-mail~
> and a ~post-to-lms~ parameter,just like
> ~org-lms-return-all-assignments~, but I'm not sure how to trick
> org-map-entries into passing those arguments on. Any hints?  Thank
> you!

Hi Matt,

If I may, I think org-ql can help you here.  It should also work much
faster than org-map-entries, because it can skip to entries with the
desired to-do keywords (although you could also use the MATCH argument
to org-map-entries to improve its speed).  Try this function (untested):

#+BEGIN_SRC elisp
(cl-defun org-lms-return-all-assignments-ql ( (send-all nil) 
(also-mail nil) (post-to-lms t))
  "By default mail all subtrees 'READY' to student recipients, unless SEND-ALL 
is non-nil.
In that case, send all marked 'READY' or 'TODO'."
  (interactive)
  (message "Mailing all READY subtrees to students")
  (let ((todo-keywords (if send-all
   '("READY" "TODO")
 '("READY"
(org-ql-select (current-buffer)
  `(todo ,@todo-keywords)
  :action `(ol-send-just-one ,also-mail ,post-to-lms
#+END_SRC




Re: [O] lisp: scoping vars in repetitive defuns

2019-09-18 Thread Joost Kremers



On Wed, Sep 18 2019, Matt Price wrote:

Is thre away to do that kind of destructuring bind -- which
binds *everything* in the plist, without knowing the symbol 
names in

advance? that would be really great.


let-alist perhaps?


--
Joost Kremers
Life has its moments



Re: [O] lisp: scoping vars in repetitive defuns

2019-09-18 Thread Matt Price
This is fun, thanks John. I really like the plist version put would also
like to loop through the variables in a let statement somehow.

I think what I'm missing is the equivalent of a javascript implicit
destructuring construct:

let { } = object;

which will define new variables prop1, prop2... forever enumerable property
of the object.  Is thre away to do that kind of destructuring bind -- which
binds *everything* in the plist, without knowing the symbol names in
advance? that would be really great.



On Wed, Sep 18, 2019 at 8:48 AM John Kitchin 
wrote:

> You don't really need a macro for this I think. I see it leads to pretty
> clean looking code, but as you noted at the expense of edebuggable
> functions. I don't think you need the lexical-let in your macro though.
> With empty arguments I am not sure it does anything.
>
> Here are some other approaches to do what you want. I wasn't
> able to test these, but I think they are close to correct and would
> provide edebuggable functions for you. The plist is more flexible and
> future proof, you can add anything you want to it, and it won't mess up
> existing functions. The first approach you can add what you want to the
> end of the list, but you can't change the order without (probably)
> messing existing functions up.
>
> #+BEGIN_SRC emacs-lisp
> (require 'f)
>
> (defun dh-variables ()
>   "Return a list of variables for the problem at point."
>   (let* ((gh (org-entry-get (point) "GITHUB"))
>  (base (org-entry-get (point) "ORG_LMS_ASSIGNMENT_DIRECTORY"))
>  (findFiles (list
>  (format "Reflection/%s.md" gh)
>  (format "students/%s.md" gh)))
>  (browseFiles '("index.html"))
>  (testOutput "TestResults/testresults.html")
>  (testCommand "MARKING=instructor npm test"))
> (list gh base findFiles browseFiles testOutput testCommand)))
>
> ;; Here we assign all the values from the function above to variable names.
> (defun dh-view ()
>   "Open viewable files in browser"
>   (destructuring-bind
>   (gh base findFiles browseFiles testOutput testCommand)
>   (dh-variables)
> (loop for f in browseFiles
>   do
>   (browse-url-of-file (f-join base f)
>
>
> ;; alternative with a plist
> (defun dh-variables ()
>   "Return a plist of variables for the problem at point."
>   (let* ((gh (org-entry-get (point) "GITHUB"))
>  (base (org-entry-get (point) "ORG_LMS_ASSIGNMENT_DIRECTORY"))
>  (findFiles (list
>  (format "Reflection/%s.md" gh)
>  (format "students/%s.md" gh)))
>  (browseFiles '("index.html"))
>  (testOutput "TestResults/testresults.html")
>  (testCommand "MARKING=instructor npm test"))
> (list :gh gh
>   :base base
>   :findFiles findFiles
>   :browseFiles browseFiles
>   :testOutput testOutput
>   :testCommand testCommand)))
>
>
> (defun dh-view ()
>   "Open viewable files in browser"
>   (loop for f in (plist-get (dh-variables) :browseFiles)
> do
> (browse-url-of-file (f-join base f
>
>
> ;; Or with the plist as an argument
> (defun dh-view (var-plist)
>   "Open viewable files in browser"
>   (loop for f in (plist-get var-plist :browseFiles)
> do
> (browse-url-of-file (f-join base f
>
>
> ;; called like this (dh-view (dh-variables))
> #+END_SRC
>
> Matt Price  writes:
>
> > On Tue, Sep 17, 2019 at 8:46 AM John Kitchin 
> > wrote:
> >
> >> I don't totally understand what you are trying to do here.
> >>
> >
> > I think the explanation was a little unclear!
> >
> >
> >> If this were Python, it sounds like you want some kind of class that
> >> stores a variable and reuses it several different functions? Something
> kind
> >> of similar to that in elisp is a closure, which is like what you
> described.
> >> For example, here, we define a variable a, and then define two functions
> >> that use it persistently.
> >>
> >>
> >> I think you can wrap this in a macro to make new functions, e.g.
> >>
> >> #+BEGIN_SRC emacs-lisp
> >> (defmacro f-maker (a)
> >>   `(lexical-let ((a ,a))
> >>  (defun f1 (x)
> >>(* a x))
> >>
> >>  (defun f2 (x)
> >>(+ a x
> >>
> >> (f-maker 3)
> >>
> >> (list (f1 2) (f2 2))
> >> #+END_SRC
> >>
> >> #+RESULTS:
> >> | 6 | 5 |
> >>
> >> This is basically what I want, except it turned out to be easier to just
> > wrap the body forms in a let *within*the function.  THis is what I came
> up
> > with:
> >
> > #+BEGIN_SRC emacs-lisp
> >
> > (defmacro dh-factory (name body  docstring)
> > "A helper macro that sets up the environment to simplify defining
> multiple
> > functions with the same environment variables. NAME will bcome the
> functin
> > name, BODY is a list containing the lisp forms specific to the function,
> > and DOCSTRING is an optional ... docstring.  NAME wil lbe wrapped in a
> > `let` statement setting all the remelvant 

Re: [O] Bug: Org commit d07d8ff41 breaks square-brace links in recent Emacs. [9.2.6 (release_9.2.6-538-g23113f @ /home/kfogel/src/org-mode/lisp/)]

2019-09-18 Thread Karl Fogel
On 18 Sep 2019, Marco Wahl wrote:
>Karl Fogel  writes:
>> Hi.  It appears that commit d07d8ff4163 in Org Mode causes 
>> square-brace-enclosed links to display incorrectly.
>>
>> The buggy behavior is simple to describe: if you write a link like this
>>
>>   [[URL][LINK-TEXT]]
>>
>> then URL will be displayed instead of LINK-TEXT (and LINK-TEXT goes unused: 
>> URL is still also given as the underlying link).
>
>This was a little accident with the regexp match groups AFAICT.  This is
>fixed in master.

Thanks for the quick fix, Marco.  I can confirm that links are working again 
now.

Best regards,
-Karl



Re: [O] Best practice for providing an Org-based application?

2019-09-18 Thread Thorsten Jolitz
Neil Jerram  writes:

Hi,

> Is there a best practice or recommended approach for preparing and
> providing an Org-based application so that others could make use of it?
>
> I've been using Org for a few years to keep track of the membership and
> 'fixing' for my choir - where 'fixing' means finding out and recording
> who can sing in each concert, who will be there for rehearsals, and so
> on.  This involves a mix of data that is private to my choir, and
> workflows and code that are potentially generic.  I don't know how many
> people in the world are both choir organisers and Emacs users, but it
> seems to me that it could be useful to separate out and document the
> generic code and workflows, so that others could use that as well as me,
> and that it would also be an interesting technical challenge.
>
> Has anyone else done something like this?  I wonder if you have
> recommendations for how to document, structure and publish this kind of
> thing?
>
> Many thanks!
>Neil

long time ago, but I once started a little project called org-bandbook,
its on my tj64 account on github.
The interesting part about is its importing funcionality for lilypond
songs from another github repo (open book I think), where a guy
transposed hundreds of popular standard (real book) tunes to lilypond with
some Ruby framework code, which I replaced by ob-lilypond code. The idea was to 
manage songs, band, concert
rehearsals etc in Org-mode, and to be able to easily transpose songs
(its ob-lilypond) for Bb or Eb instruments or so.

OTOH isn't managing a choir or band quite similar to managing a project,
and thus (ob-)taskjuggler would be a very helpful tool here?

-- 
cheers,
Thorsten




[O] org-map-entries but with arguments?

2019-09-18 Thread Matt Price
Is there a lisp trick for adding arguments to the function called by
`org-map-entries`?

I have the following function:

(cl-defun org-lms-return-all-assignments ( (send-all nil)
(also-mail nil) (post-to-lms t) )
  "By default mail all subtrees 'READY' to student recipients, unless
SEND-ALL is non-nil.
In that case, send all marked 'READY' or 'TODO'."
  (interactive)
  (message "Mailing all READY subtrees to students")
  (let ((send-condition
 (if send-all
 `(or (string= (org-element-property :todo-keyword item)
"READY")
  (string= (org-element-property :todo-keyword item)
"TODO") )
   `(string= (org-element-property :todo-keyword item) "READY")
   )))
(org-map-entries
 #'ol-send-just-one))
  (org-cycle-hide-drawers 'all))

I'd like to relay some of hte functions arguments to the one called
internally to do the work.  ~(ol-send-just-one~ takes an ~also-mail~ and a
~post-to-lms~ parameter,just like ~org-lms-return-all-assignments~, but I'm
not sure how to trick org-map-entries into passing those arguments on. Any
hints?  Thank you!


[O] Tables: Exclude headings in Row Number?

2019-09-18 Thread Nathan Neff
Hello all,

I have a table like this:


| ID |
||
|  2 |
|  3 |

and I want to know how many rows there are w/o the ID heading
and w/o the horizontal separator.  I found the
org-table-toggle-coordinate-overlays
which displays an overlay showing the row number:

https://www.evernote.com/l/AOJvD5ty6RRIBYAcSWV-047CKCHT5NIAhl8

However, the heading is included in the row number (which makes sense).

Is there a way to ignore lines above a heading (or mark a heading in some
way?

I found a way to add a seq. number by using Calc [1] but I was wondering if
there's a way to tell the org-table-toggle-coordinate-overlays not to count
the
heading.

Thanks,
--Nate

[1]


| num | ID |
|-+|
|   1 | A  |
|   2 | B  |
|   3 | C  |
|   4 ||
|   5 | E  |
#+TBLFM: $1=vlen(@I..0)

https://stackoverflow.com/questions/9267050/how-to-achieve-a-row-index-column-in-emacs-org-mode-using-a-calc-column-rule


Re: [O] lisp: scoping vars in repetitive defuns

2019-09-18 Thread John Kitchin
You don't really need a macro for this I think. I see it leads to pretty
clean looking code, but as you noted at the expense of edebuggable
functions. I don't think you need the lexical-let in your macro though.
With empty arguments I am not sure it does anything.

Here are some other approaches to do what you want. I wasn't
able to test these, but I think they are close to correct and would
provide edebuggable functions for you. The plist is more flexible and
future proof, you can add anything you want to it, and it won't mess up
existing functions. The first approach you can add what you want to the
end of the list, but you can't change the order without (probably)
messing existing functions up.

#+BEGIN_SRC emacs-lisp
(require 'f)

(defun dh-variables ()
  "Return a list of variables for the problem at point."
  (let* ((gh (org-entry-get (point) "GITHUB"))
 (base (org-entry-get (point) "ORG_LMS_ASSIGNMENT_DIRECTORY"))
 (findFiles (list
 (format "Reflection/%s.md" gh)
 (format "students/%s.md" gh)))
 (browseFiles '("index.html"))
 (testOutput "TestResults/testresults.html")
 (testCommand "MARKING=instructor npm test"))
(list gh base findFiles browseFiles testOutput testCommand)))

;; Here we assign all the values from the function above to variable names.
(defun dh-view ()
  "Open viewable files in browser"
  (destructuring-bind
  (gh base findFiles browseFiles testOutput testCommand)
  (dh-variables)
(loop for f in browseFiles
  do
  (browse-url-of-file (f-join base f)


;; alternative with a plist
(defun dh-variables ()
  "Return a plist of variables for the problem at point."
  (let* ((gh (org-entry-get (point) "GITHUB"))
 (base (org-entry-get (point) "ORG_LMS_ASSIGNMENT_DIRECTORY"))
 (findFiles (list
 (format "Reflection/%s.md" gh)
 (format "students/%s.md" gh)))
 (browseFiles '("index.html"))
 (testOutput "TestResults/testresults.html")
 (testCommand "MARKING=instructor npm test"))
(list :gh gh
  :base base
  :findFiles findFiles
  :browseFiles browseFiles
  :testOutput testOutput
  :testCommand testCommand)))


(defun dh-view ()
  "Open viewable files in browser"
  (loop for f in (plist-get (dh-variables) :browseFiles)
do
(browse-url-of-file (f-join base f


;; Or with the plist as an argument
(defun dh-view (var-plist)
  "Open viewable files in browser"
  (loop for f in (plist-get var-plist :browseFiles)
do
(browse-url-of-file (f-join base f


;; called like this (dh-view (dh-variables))
#+END_SRC

Matt Price  writes:

> On Tue, Sep 17, 2019 at 8:46 AM John Kitchin 
> wrote:
>
>> I don't totally understand what you are trying to do here.
>>
>
> I think the explanation was a little unclear!
>
>
>> If this were Python, it sounds like you want some kind of class that
>> stores a variable and reuses it several different functions? Something kind
>> of similar to that in elisp is a closure, which is like what you described.
>> For example, here, we define a variable a, and then define two functions
>> that use it persistently.
>>
>>
>> I think you can wrap this in a macro to make new functions, e.g.
>>
>> #+BEGIN_SRC emacs-lisp
>> (defmacro f-maker (a)
>>   `(lexical-let ((a ,a))
>>  (defun f1 (x)
>>(* a x))
>>
>>  (defun f2 (x)
>>(+ a x
>>
>> (f-maker 3)
>>
>> (list (f1 2) (f2 2))
>> #+END_SRC
>>
>> #+RESULTS:
>> | 6 | 5 |
>>
>> This is basically what I want, except it turned out to be easier to just
> wrap the body forms in a let *within*the function.  THis is what I came up
> with:
>
> #+BEGIN_SRC emacs-lisp
>
> (defmacro dh-factory (name body  docstring)
> "A helper macro that sets up the environment to simplify defining multiple
> functions with the same environment variables. NAME will bcome the functin
> name, BODY is a list containing the lisp forms specific to the function,
> and DOCSTRING is an optional ... docstring.  NAME wil lbe wrapped in a
> `let` statement setting all the remelvant variables."
>   `(lexical-let (())
>  (defun ,name ,()
>,docstring
>(interactive)
>(let* ((gh (org-entry-get (point) "GITHUB"))
>  (base (org-entry-get (point) "ORG_LMS_ASSIGNMENT_DIRECTORY"))
>  (findFiles `( ,(concat "Reflection/" gh ".md") ,(concat
> "students/" gh ".json")))
>  (browseFiles `( "index.html" ))
>  (testOutput "TestResults/testresults.html")
>  (testCommand "MARKING=instructor npm test"))
>  ,@body
>
> (dh-factory dh-find-files
> ((dolist (f findFiles)
>(message "%s" (concat base "/" f))
>(if (file-exists-p (concat base "/" f))
>(find-file-other-window (concat base "/" f) )
>  (message "File %s does not exist, 

Re: [O] Bug: Org commit d07d8ff41 breaks square-brace links in recent Emacs. [9.2.6 (release_9.2.6-538-g23113f @ /home/kfogel/src/org-mode/lisp/)]

2019-09-18 Thread Marco Wahl
Hi.

Karl Fogel  writes:

> Hi.  It appears that commit d07d8ff4163 in Org Mode causes 
> square-brace-enclosed links to display incorrectly.
>
> The buggy behavior is simple to describe: if you write a link like this
>
>   [[URL][LINK-TEXT]]
>
> then URL will be displayed instead of LINK-TEXT (and LINK-TEXT goes unused: 
> URL is still also given as the underlying link).

This was a little accident with the regexp match groups AFAICT.  This is
fixed in master.


Thanks,
-- 
Marco