Re: [O] [RFC] Remove Org Struct mode

2017-08-22 Thread Eric S Fraga
On Tuesday, 22 Aug 2017 at 08:58, Marcin Borkowski wrote:

[...]

> Out of curiosity: did anyone consider using lentic
> (https://github.com/phillord/lentic) for that?

I did look at this in the past but it seemed overkill for emails... and
I use babel when programming otherwise so don't really need it.  YMMV,
of course!

-- 
: Eric S Fraga via Emacs 26.0.50, Org release_9.0.9-787-g197c58


signature.asc
Description: PGP signature


Re: [O] Word-counting in a subtree

2017-08-22 Thread Simon Guest
[copy to list]

A few years ago I wrote org-wc.el, which is on MELPA.  It uses overlays to
display a word count against each heading.

Just install the package, and run org-wc-display.

https://github.com/tesujimath/org-wc

Hope that helps.

cheers,
Simon

On 22 August 2017 at 09:34, Jacopo De Simoi  wrote:

> On Monday, August 21, 2017 2:09:25 PM EDT Eric S Fraga wrote:
> > On Monday, 21 Aug 2017 at 13:21, Jacopo De Simoi wrote:
> > > tl;dr
> > >
> > > Is there a way to create a token on a subtree header that would count
> > > words in the subtree and [optionally] mark a maximum allowed number of
> > > words?
> > I cannot help you directly but what I do is: narrow the region to the
> > sub-tree while writing and then simply execute M-x count-words RET every
> > now and again.
>
> this has the drawback that it also counts words in the header line; except
> this, could work as a temporary solution, but I'd still like to cook up
> some
> tag integrated with org
>
> >
> > There is a wc-mode which displays the number of words/chars in the
> > modeline but my modeline is already too busy for this...
>
> Indeed modelines are crowded these days…
>
>
>


Re: [O] Word-counting in a subtree

2017-08-22 Thread Nicolas Goaziou
Hello,

Jacopo De Simoi  writes:

> this has the drawback that it also counts words in the header line; except 
> this, could work as a temporary solution, but I'd still like to cook up some 
> tag integrated with org

What about something like this (untested):

  (defun my-count-words (&optional ignore-headings beg end)
(save-restriction
  (narrow-to-region (or beg (point-min)) (or end (point-max)))
  (let ((count 0)
(count-words-in-string
 (lambda (s) (length (split-string s "[^[:word:]]" t)
(org-element-map
(org-element-parse-buffer)
'(clock code entity example-block fixed-width footnote-reference
inline-src-block latex-fragment latex-environment
link macro plain-text src-block timestamp verbatim)
  (lambda (datum)
(pcase (org-element-type datum)
  (`plain-text
   (unless (and ignore-headings
(memq (org-element-type
   (org-element-property :parent datum))
  '(headline inlinetask)))
 (cl-incf count (funcall count-words-in-string datum
  ;; Count contents in words.
  ((or `code `example-block `fixed-width `latex-environment
   `latex-fragment `src-block `verbatim)
   (cl-incf count (funcall count-words-in-string
   (org-element-property :value datum
  ;; Object counting as a single word.
  (`(or `entity `inline-src-block `macro `timestamp)
   (cl-incf count))
  (`link
   ;; Links with contents are handled recursively by
   ;; `org-element-map'.
   (unless (org-element-contents datum) (cl-incf count)))
  (`footnote-reference
   (pcase (org-footnote-get-definition
   (org-element-property :label datum))
 (`(,_ ,_ ,_ ,definition)
  (cl-incf count (funcall count-words-in-string 
definition)))
  ;; Do not blindly count footnote definitions and inline
  ;; references contents. We want to limit ourselves to
  ;; definitions actually referenced in the part of the document
  ;; we're parsing.
  nil nil '(footnote-definition footnote-reference) t)
;; Return words count.
count)))

Note that some parts are really arbitrary (e.g., how to count a src
block...).

Regards,

-- 
Nicolas Goaziou



Re: [O] [RFC] Remove Org Struct mode

2017-08-22 Thread Kaushal Modi
On Sun, Aug 20, 2017 at 9:58 AM Nicolas Goaziou 
wrote:

> Hello,
>
> I would like to remove Org Struct minor mode from Org code base.


Like many others who replied here, I also do not use Org Struct. So its
removal will have no effect on my workflow.


> 5. There are alternatives. E.g., outshine.el, outline-minor-mode, ...
>

I use one of those alternatives.. outshine.el.


> I'm not talking about OrgTbl mode (yet). OrgTbl mode is different: it
> doesn't suffer from points 1, 3 end 5.
>

Thanks. I find orgtbl-mode very useful.
-- 

Kaushal Modi


Re: [O] [RFC] Remove Org Struct mode

2017-08-22 Thread Kaushal Modi
On Mon, Aug 21, 2017 at 8:00 AM Michael Brand 
wrote:

> Hi all
>
> If I understand correctly orgstruct-mode has much more convenient key
> bindings like TAB and its variants for cycling than outshine.el or
> outline-minor-mode which is a big advantage for me. When point is on a
> heading also the other key bindings are just the same as in Org mode.
> This was my reason to give up outshine.el
>

Hi Michael,

I use both of the Org-like features in outshine. I have these variables set
in my config:

(setq outshine-use-speed-commands t)
(setq outshine-org-style-global-cycling-at-bob-p t)

Also check outshine-speed-commands-default and outshine-speed-commands-user
(setup is similar to that of Org Speed Keys).

-- 

Kaushal Modi


Re: [O] multiple agenda views -- sticky agendas?, buffer renaming?

2017-08-22 Thread Alain . Cochard


Bastien writes on Mon  3 Jul 2017 07:09:

 > alain.coch...@unistra.fr writes:
 > 
 > > I want my *Org Agenda* buffer to be open at all times, but I still
 > > want to be able to (say) match as many different tags as desired.
 > >
 > > Googling and searching the archives suggested 2 possible ways: (1)
 > > use of sticky agenda views and (2) use 'M-x rename-uniquely'.

 > "Sticky" agenda buffers means that agenda buffers won't be recreated
 > each time you call M-x org-agenda.  I'm not sure this is exactly what
 > you mean by "my *Org Agenda* buffer to be open at all times", is it?
 > 
 > Also I'm not sure what is the exact error you are pointing to: can
 > you restate it by saying what you expected from what action, and what
 > you got instead?

Hi Bastien, and thank you very much for the feedback.  I am sorry for
the delay in replying.

I now try to explain myself more clearly.

Say I have emacs open, with a single frame.  If I do

M-x org-agenda a

I see what I call my "agenda" (not sure this is the proper
terminology), in what I assumed was called an "*Org Agenda* buffer" --
I realize now how confusing this could have been, because it seems
that all buffers obtained from some 'M-x org-agenda' command are named
"Org-agenda."

If I now do

M-x make-frame

I get a 2nd frame.  I would like to be able to work with that 2nd
frame without modifying the content of the 1st frame.  This is what I
meant by "my *Org Agenda* buffer to be open at all times" (in the 1st
frame in this example).

But if, in the 2nd frame, I do

M-x org-agenda m tag1

the contents of *both* the 1st and 2nd frames are modified
accordingly.  I understand this to be normal, but this is not what I
want, because my agenda is no longer showing in the 1st frame.

I was assuming sticky agendas would produce the behavior I wish, so
(starting fresh), I try

M-x org-agenda * a

then

M-x make-frame

and, in the 2nd, newly created, frame:

M-x org-agenda m tag1

So far, the behavior is as I expect: my agenda is still in the 1st
frame while, in the 2nd one, I have the *Org Agenda(m)* buffer, which
I can use as expected (typically, put the cursor on some line, press
, etc.).  It is from this point that it appears to me to go
wrong; specifically, if I try to do, still in the 2nd frame:

M-x org-agenda m tag2

then, as soon as the 'm' is typed, the following message appears in
the minibuffer: "Sticky Agenda buffer, use `r' to refresh".  But
typing 'r' does not do any good.

The behavior that I expect is (1) to not see the above mentioned
message in the minibuffer, (2) to be able to finish typing 'M-x
org-agenda m tag2', (3) have the *Org Agenda(m)* buffer relevant to
tag2.

In fact, I made progress since my initial email:  I had never paid
attention to the following message, which appear after the first tag
search: 

Press `C-u r' to search again with new search string

I had ignored it because for me it is more convenient to always use
the same key combination for a given operation (in this case 'C-c a m'
for a tag search).

If I do use 'C-u r', then I can indeed perform another tag search (and
others afterward), and I can say that the use of a sticky agenda does
solve my initial problem!

The somehow funny thing is that after this 'C-u r', I can again use
'M-x org-agenda m some_tag'.  In fact I cannot use 'M-x org-agenda m
some_tag' twice in a row: I have to intermingle it with at least one
instance of 'C-u r some_tag'.

So I could reformulate my initial email by saying that tag search does
not behave the same way whether the agenda is sticky or not: with a
non sticky agenda, one may always use 'M-x org-agenda m some_tag' for
a tag search whereas this is not possible with a sticky agenda.

I hope I could make myself clear this time.
Regards,
alain


-- 
EOST (École et Observatoire des Sciences de la Terre) 
IPG (Institut de Physique du Globe) | alain.coch...@unistra.fr
5 rue René Descartes   [bureau 106] | Phone: +33 (0)3 68 85 50 44 
F-67084 Strasbourg Cedex, France| Fax:   +33 (0)3 68 85 01 25 


Re: [O] [RFC] Remove Org Struct mode

2017-08-22 Thread Aaron Ecay
Hi Nicolas,

2017ko abuztuak 20an, Nicolas Goaziou-ek idatzi zuen:
> 
> Hello,
> 
> I would like to remove Org Struct minor mode from Org code base.

FWIW, +1 from me.  I often bumped up against org-struct related
difficulties when coding on org, and I can easily imagine that removing
it will make maintenance much easier while (as you pointed out) still
leaving alternative solutions for recovering (most of) its
functionality.

-- 
Aaron Ecay



Re: [O] [RFC] Remove Org Struct mode

2017-08-22 Thread Carsten Dominik
Hi Nicolas,

I have not problems with removing orgstruct-mode, it is indeed a bad hack
and I am no longer using it.

I am glad you are not planning to remove orgtbl-mode.  In particular, in
connection with radio tables, it is a feature that I use constantly, so I
would object strongly to removing it.

Carsten

On Sun, Aug 20, 2017 at 3:57 PM, Nicolas Goaziou 
wrote:

> Hello,
>
> I would like to remove Org Struct minor mode from Org code base. Here is
> the rationale:
>
> 1. It is broken. It might look like using Org in another buffer, but it
>is not. In particular, it just cannot cope with lists, indentation,
>filling in, e.g., Message mode, as soon as we try something
>non-trivial. Really, that's a poor-man's Org mode.
>
> 2. Its implementation is very hackish. In particular, it is not modular
>at all. It rewrites some core functions according to the major mode
>in use. For example `org-fill-function' tries to handle specially
>text in a Message mode buffer, basically short-circuiting regular
>behaviour. There no support for other major modes. If we want some,
>we need to hard-code it.
>
> 3. Due to previous point, some basic Org functions are sub-optimal
>because they preserve compatibility with Org Struct mode. For example
>`org-forward-heading-same-level' must process every headline past the
>current one and check their level until an appropriate one is found.
>It would be faster to go looking for the next headline according to
>the number of stars we want.
>
> 4. It is somewhat outside Org mode's scope to provide such a feature. It
>is tempting to provide everything we can think of, but we should
>focus on the main task: handle Org files, i.e., files written in Org
>compatible syntax.
>
> 5. There are alternatives. E.g., outshine.el, outline-minor-mode, ...
>
> I _do_ use `orgstruct++-mode'. But it is broken beyond repair.
> Alternatives, which do not need to pay a technical debt, are certainly
> better, or, at least, a saner ground for improvement.
>
> I'm not opposed to an Org struct mode living in ELPA. But, as pointed
> out, it is difficult to extract from code base without rewriting it
> completely. If alternatives are serious enough, that would be
> re-inventing the wheel, too.
>
> The only thing that would be missing, AFAIK, is plain list handling.
> However, I'm quite certain it is possible to re-use most code from
> "org-list.el", using a dumbed down `org-list-struct' function. Indeed,
> currently, `org-list-struct' requires to know about inlinetasks,
> drawers, blocks... i.e., most of the Org syntax. This is not an option
> in foreign buffers. Once `org-list-struct' (and maybe `org-in-item-p')
> are simplified, other functions in "org-list.el" can be used as is.
>
> I'm not talking about OrgTbl mode (yet). OrgTbl mode is different: it
> doesn't suffer from points 1, 3 end 5. It is easier to extract it as an
> external library, which someone should ultimately do.
>
> To sum it up, I offer to remove `orgstruct-mode' (and
> `orgstruct++-mode') from the code base. I can also offer my help to
> anyone willing to extract some `list-minor-mode' and `table-minor-mode'
> from Org.
>
> WDYT?
>
>
> Regards,
>
> --
> Nicolas Goaziou0x80A93738
>
>


Re: [O] [RFC] Remove Org Struct mode

2017-08-22 Thread Michael Brand
Thanks for pointing out speed keys in outshine.el that I was not aware
of. However I still failed.

My requirements for orgstruct-mode or its replacement are very limited
compared to what orgstruct-mode or outshine.el do or intend to do:

1) Only headings, no lists
2) No structure editing, only cycling and navigation
3) Key bindings accessible directly also in vi emulation
4) Key bindings exactly like Org
5) Headings also in block-indented comments (on its own line)
6) No syntax highlighting of headings
7) Org original special folding of the ARCHIVE tag

Note that I need all this only for a limited amount of Org functions
(a subset of orgstruct-setup):

- TAB (org-cycle)
- S-TAB (org-cycle)
- C-TAB (org-force-cycle-archived)
- C-c C-f (org-forward-heading-same-level)
- C-c C-b (org-backward-heading-same-level)
- C-c C-n (outline-next-visible-heading)
- C-c C-p (outline-previous-visible-heading)
- C-c C-u (outline-up-heading)

All items 3)..7) are supported in orgstruct-mode, in outshine.el I was
not able to make them work. If I want to use the speed keys in
outshine.el with vi emulation I have to switch to Emacs mode and back
where in orgstruct-mode I can stay and use simply TAB/S-TAB/C-TAB.

Michael



[O] merging subtrees (in a syllabus)

2017-08-22 Thread Matt Price
I maintain syllabi for courses htat have *discussion* ocmponents and *lab*
ocmponents; these are often quite separate from one another.

I end up with trees that look like this:

* Outline

** <2017-09-12 Tue> (Week {{{n}}}) Hacking History in the Himalaya
Why we should write history, why everyone should do it, and why that means
we need the Web.  Hacker cultures, collaborative learning, knowledge
sharing, non-expert culture. And a few words about the world's
third-tallest mountain.

*** Background:
- [[
http://www.journalofamericanhistory.org/issues/952/interchange/index.html][JAH
- The Promise of Digital History]], [[
http://writinghistory.trincoll.edu/revisioning/tanaka-2012-spring/][Pasts
in a Digital Age]]
-
*** Lab 01: Getting Started
- HTML and Markdown
- Some Tools: Github, Dropbox, Atom Text Editor
- About Our Partners

** <2017-09-19 Tue> (Week {{{n}}}) Language of the Web
The Web is written in a language called HTML, with some help from other
lanugages called CSS and Javascript. The nonlinear and interactive
properties of these languages afford new possibilities for storytelling. We
explore how the Internet works, and what that means for historical
narrative.
*** Readings
- Vannevar Bush, "[[
http://www.theatlantic.com/magazine/archive/1969/12/as-we-may-think/3881/][As
We May Think]]"
- Tim Berners-Lee, /Weaving the Web/
[[file:readings/berners-lee-weaving-web.pdf][Ch. 2,4]].
- Edward L. Ayers, "[[http://www.vcdh.virginia.edu/Ayers.OAH.html][History
in Hypertext]]"
- Rus Shuler, "[[
http://www.theshulers.com/whitepapers/internet_whitepaper/index.html][How
Does the Internet Work?]]"
*** Lab 02: Understanding HTML
*Resources:* [[http://jsbin.com/#html,live][JSBin online HTML/Javascript
editor]]; [[http://codeacademy.net][codeacademy courses]]; [[
http://en.wikipedia.org/wiki/HTML][on Wikipedia]]; [[
http://www.w3.org/MarkUp/Guide/][w3 guide]]; also cf. Zotero Bibliography

--

Because the course readings and hte lab are often separate, it can be
difficult and confusing to maintain the course outline in its final form.
Id like to be able, instead, to maintain the labs and readings separately,
and /merge/ them to produce the final document.  So I'd start with
something like this:

* Outline
** Week {{{n}}}
** Week {{{n}}}

* Discussion Topics
** Hacking History in the Himalaya
*** Readings
- 
- ...
** The Language of the Web
*** Readings
- ...
- ...

* Labs
** Getting Started
- ...
- ...
- ...
** Understanding HTML
- ...
- ...


And then I'd run some elisp that mashes them all up together, and give that
to the students, since I think that'll make it easier for them to read.

Anyone on the list have any ideas? If it also comes with a thought about
how to generate an org date objet form an initial seed and a session
number, that's be fabulous too.

Thank you as always!

Matt


[O] Bug: export to markdown invalid URL

2017-08-22 Thread Fabio Leimgruber
Hello everyone,

using latest master, an org file containing just the link

#+BEGIN_SRC org
[[http://orgmode.org/img/org-mode-unicorn-logo.png]]
#+END_SRC

on export to markdown with =C-c C-e m m= produces the md file

#+BEGIN_EXAMPLE
# Table of Contents



![img](http//orgmode.org/img/org-mode-unicorn-logo.png)
#+END_EXAMPLE

containing an invalid URL.

Best Regards,

--
Fabio Leimgruber



Re: [O] Bug: export to markdown invalid URL

2017-08-22 Thread Jay Kamat
Hi,

Thanks for catching that. That was my fault, for failing to test
commit f3d7284ebd0c6e8248f7c3c444937270402b0ba6 properly.

See http://lists.gnu.org/archive/html/emacs-orgmode/2017-08/msg00147.html
for the previous thread.

I've attached a trivial patch which appears to fix the issue for me,
but I don't know if there's a cleaner way to do it or not (is there a
link property that keeps the ':' in either the link or the type?).

Thanks,
-Jay

On Tue, Aug 22, 2017 at 5:16 PM, Fabio Leimgruber
 wrote:
> Hello everyone,
>
> using latest master, an org file containing just the link
>
> #+BEGIN_SRC org
> [[http://orgmode.org/img/org-mode-unicorn-logo.png]]
> #+END_SRC
>
> on export to markdown with =C-c C-e m m= produces the md file
>
> #+BEGIN_EXAMPLE
> # Table of Contents
>
>
>
> ![img](http//orgmode.org/img/org-mode-unicorn-logo.png)
> #+END_EXAMPLE
>
> containing an invalid URL.
>
> Best Regards,
>
> --
> Fabio Leimgruber
>
From 5d92257575e497e0955b3414fb1e1a69e5ea97f8 Mon Sep 17 00:00:00 2001
From: Jay Kamat 
Date: Tue, 22 Aug 2017 17:28:28 -0400
Subject: [PATCH] ox-md.el: Fix missing ':' in exported markdown image links

* lisp/ox-md.el (org-md-link): Append ':' to the type of non-file
  image links.
---
 lisp/ox-md.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 0dd1be095..ac94ba648 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -432,7 +432,7 @@ a communication channel."
 		   (org-export-get-reference destination info
  ((org-export-inline-image-p link org-html-inline-image-rules)
   (let ((path (let ((raw-path (org-element-property :path link)))
-		(cond ((not (equal "file" type)) (concat type raw-path))
+		(cond ((not (equal "file" type)) (concat type ":" raw-path))
 			  ((not (file-name-absolute-p raw-path)) raw-path)
 			  (t (expand-file-name raw-path)
 	(caption (org-export-data
-- 
2.11.0



Re: [O] Bug: export to markdown invalid URL

2017-08-22 Thread Nicolas Goaziou
Hello,

Jay Kamat  writes:

> Subject: [PATCH] ox-md.el: Fix missing ':' in exported markdown image links
>
> * lisp/ox-md.el (org-md-link): Append ':' to the type of non-file
>   image links.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou



Re: [O] Bug: export to markdown invalid URL

2017-08-22 Thread Jay Kamat
Hi again,

sorry for the repeated emails, but I think I've come up with a better
solution to this issue, to just use the raw link target in the target
of the markdown export, which I've attached to this email. Feel free
to pick either one of these patches or come up with something better.

Hope this gets fixed soon,
-Jay


On Tue, Aug 22, 2017 at 5:33 PM, Jay Kamat  wrote:
> Hi,
>
> Thanks for catching that. That was my fault, for failing to test
> commit f3d7284ebd0c6e8248f7c3c444937270402b0ba6 properly.
>
> See http://lists.gnu.org/archive/html/emacs-orgmode/2017-08/msg00147.html
> for the previous thread.
>
> I've attached a trivial patch which appears to fix the issue for me,
> but I don't know if there's a cleaner way to do it or not (is there a
> link property that keeps the ':' in either the link or the type?).
>
> Thanks,
> -Jay
>
> On Tue, Aug 22, 2017 at 5:16 PM, Fabio Leimgruber
>  wrote:
>> Hello everyone,
>>
>> using latest master, an org file containing just the link
>>
>> #+BEGIN_SRC org
>> [[http://orgmode.org/img/org-mode-unicorn-logo.png]]
>> #+END_SRC
>>
>> on export to markdown with =C-c C-e m m= produces the md file
>>
>> #+BEGIN_EXAMPLE
>> # Table of Contents
>>
>>
>>
>> ![img](http//orgmode.org/img/org-mode-unicorn-logo.png)
>> #+END_EXAMPLE
>>
>> containing an invalid URL.
>>
>> Best Regards,
>>
>> --
>> Fabio Leimgruber
>>
From 743daf53843a29b1202553345b4fc298ac87c74e Mon Sep 17 00:00:00 2001
From: Jay Kamat 
Date: Tue, 22 Aug 2017 17:28:28 -0400
Subject: [PATCH] ox-md.el: Fix missing ':' in exported markdown image links

* lisp/ox-md.el (org-md-link): Use raw-link for markdown link target
  instead of merging type and raw-path
---
 lisp/ox-md.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 0dd1be095..9afb5227e 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -431,8 +431,9 @@ a communication channel."
 		   description
 		   (org-export-get-reference destination info
  ((org-export-inline-image-p link org-html-inline-image-rules)
-  (let ((path (let ((raw-path (org-element-property :path link)))
-		(cond ((not (equal "file" type)) (concat type raw-path))
+   (let ((path (let ((raw-path (org-element-property :path link))
+			  (raw-link (org-element-property :raw-link link)))
+		(cond ((not (equal "file" type)) raw-link)
 			  ((not (file-name-absolute-p raw-path)) raw-path)
 			  (t (expand-file-name raw-path)
 	(caption (org-export-data
-- 
2.11.0



Re: [O] Bug: export to markdown invalid URL

2017-08-22 Thread Nicolas Goaziou
Jay Kamat  writes:

> sorry for the repeated emails, but I think I've come up with a better
> solution to this issue, to just use the raw link target in the target
> of the markdown export, which I've attached to this email. Feel free
> to pick either one of these patches or come up with something better.

I think the current patch is fine. Yours is equivalent, but since we
already bound `raw-path', we might as well use it.

> Hope this gets fixed soon,

Isn't it already the case?

Regards,



Re: [O] [RFC] Remove Org Struct mode

2017-08-22 Thread Eric Abrahamsen
Nicolas Goaziou  writes:

> Hello,
>
> I would like to remove Org Struct minor mode from Org code base. Here is
> the rationale:
>
> 1. It is broken. It might look like using Org in another buffer, but it
>is not. In particular, it just cannot cope with lists, indentation,
>filling in, e.g., Message mode, as soon as we try something
>non-trivial. Really, that's a poor-man's Org mode.
>
> 2. Its implementation is very hackish. In particular, it is not modular
>at all. It rewrites some core functions according to the major mode
>in use. For example `org-fill-function' tries to handle specially
>text in a Message mode buffer, basically short-circuiting regular
>behaviour. There no support for other major modes. If we want some,
>we need to hard-code it.

+1. I've tried two or three times to refactor it, and it was a
nightmare. I only use lists in orgstruct-mode, so I'd be happy with a
very reduced version, or nothing at all.




[O] dynamic date arithmetic in a macro or otherwise (simulating a "date counter")?

2017-08-22 Thread Matt Price
On Thu, Aug 17, 2017 at 3:25 PM, Matt Price  wrote:

> I'd love to be able generate dates dynamically using the {{{n}}} org
> macro, or some other mechanism.  I don't immediately see how that would be
> possible but maybe someone can guide me.  I'd want to do something
> equivalent to this pseudo-elisp:
>
> (let ((base-date 2017-09-05))
>   (+ base-date (* 7 {{{n}}}))
>
> I haven't looked into how date objects are parsed in org-mode, though, so
> I have no idea how hard it would be to actually implement something like
> this.
>

I made some progress on this (but not much).

I defined a simple macro that adds times together and creates a timestamp
that org can read -- in fact, this one adds some text as well:

#+MACRO: w (eval (format-time-string "Week {{{n(week)}}} (<%Y-%m-%d %a>)"
(time-add (encode-time 0 0 0 17 9 2017) (days-to-time (* 7 1 )

This does everything that I want *except* dynamically adding time to the
previous macro call.  I tried defining a dynamic version:

#+MACRO: w (eval (format-time-string "Week {{{n(week)}}} (<%Y-%m-%d %a>)"
(time-add (encode-time 0 0 0 17 9 2017) (days-to-time (* 7 $1 ))

And then calling it with

{{{w({{{n}}})}}}

But unsurprisingly and appropriately, that didn't work.

I also took a look at the patch Nicolas used to implement the {{{n}}} macro
(I've reattached it here for convenience only!).  It defines
`org-macro--counter-initialize` and calls it from inside
`org-macro-templates-initialize`.  I guess I could copy that strategy but
then I'd be maintaining my own copy of org-macro-templates-initialize,
which seems like a terrible idea.

So, I'm not sure how best to proceed. For my specific use-case, something
like this would be a huge timesaver when multiplied over semesters/years.
But I also wonder whether maybe other people would enjoy being able to do
date arithmetic inside org files (and outside of tables -- I know from
Sacha's 2015 blog post  that this is possible inside a table --
http://sachachua.com/blog/2015/06/using-your-own-emacs-lisp-functions-in-org-mode-table-calculations-easier-dosage-totals/).
If other people would also use such code, I could try to hack something
together for submission. Generalizable functions will be hard for me to
write because I am sometimes a bit dense. I would love to hear suggestions
from the group...


> Thank you everyone!
>

^^ this still applies!
Matt
From 980b713f28596c7f6486dc1ccfa82f76de7c963d Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou 
Date: Mon, 8 May 2017 12:38:38 +0200
Subject: [PATCH] org-macro: Implement the "n" macro

* lisp/org-macro.el (org-macro--counter-table): New variable.
(org-macro--counter-initialize):
(org-macro--counter-increment): New functions.
(org-macro-initialize-templates): Use new functions.

* doc/org.texi (Macro replacement): Document new macro.

* testing/lisp/test-org-macro.el (test-org-macro/n):
(test-org-macro/property): New tests.
---
 etc/ORG-NEWS   |   3 ++
 lisp/org-macro.el  |  38 +--
 testing/lisp/test-org-macro.el | 102 +++--
 3 files changed, 127 insertions(+), 16 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 3ca5b0553..b6110c412 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -197,6 +197,9 @@ contents, are now supported.
 This new function is meant to be used in back-ends supporting images
 as descriptions of links, a.k.a. image links.  See its docstring for
 details.
+ New macro : ~{{{n}}}~
+This macro creates and increment multiple counters in a document.  See
+manual for details.
  Add global macros through ~org-export-global-macros~
 With this variable, one can define macros available for all documents.
  New keyword ~#+EXPORT_FILE_NAME~
diff --git a/lisp/org-macro.el b/lisp/org-macro.el
index 71e917b71..f5ddb92e4 100644
--- a/lisp/org-macro.el
+++ b/lisp/org-macro.el
@@ -36,8 +36,11 @@
 
 ;; Along with macros defined through #+MACRO: keyword, default
 ;; templates include the following hard-coded macros:
-;; {{{time(format-string)}}}, {{{property(node-property)}}},
-;; {{{input-file}}} and {{{modification-time(format-string)}}}.
+;;   {{{time(format-string)}}},
+;;   {{{property(node-property)}}},
+;;   {{{input-file}}},
+;;   {{{modification-time(format-string)}}},
+;;   {{{n(counter,reset}}}.
 
 ;; Upon exporting, "ox.el" will also provide {{{author}}}, {{{date}}},
 ;; {{{email}}} and {{{title}}} macros.
@@ -129,7 +132,7 @@ function installs the following ones: \"property\",
 	(let ((old-template (assoc (car cell) templates)))
 	  (if old-template (setcdr old-template (cdr cell))
 		(push cell templates))
-;; Install hard-coded macros.
+;; Install "property", "time" macros.
 (mapc update-templates
 	  (list (cons "property"
 		  "(eval (save-excursion
@@ -143,6 +146,7 @@ function installs the following ones: \"property\",
   l)
 (org-entry-get nil \"$1\" 'selective)))")
 		(cons "time" "(eval (format-

Re: [O] dynamic date arithmetic in a macro or otherwise (simulating a "date counter")?

2017-08-22 Thread Sacha Chua
org-clone-subtree-with-time-shift might be a good starting point, too. It
could be interesting to be able to replace dates within text and
priorities. Good luck!

On Aug 22, 2017 7:10 PM, "Matt Price"  wrote:

>
>
> On Thu, Aug 17, 2017 at 3:25 PM, Matt Price  wrote:
>
>> I'd love to be able generate dates dynamically using the {{{n}}} org
>> macro, or some other mechanism.  I don't immediately see how that would be
>> possible but maybe someone can guide me.  I'd want to do something
>> equivalent to this pseudo-elisp:
>>
>> (let ((base-date 2017-09-05))
>>   (+ base-date (* 7 {{{n}}}))
>>
>> I haven't looked into how date objects are parsed in org-mode, though, so
>> I have no idea how hard it would be to actually implement something like
>> this.
>>
>
> I made some progress on this (but not much).
>
> I defined a simple macro that adds times together and creates a timestamp
> that org can read -- in fact, this one adds some text as well:
>
> #+MACRO: w (eval (format-time-string "Week {{{n(week)}}} (<%Y-%m-%d %a>)"
> (time-add (encode-time 0 0 0 17 9 2017) (days-to-time (* 7 1 )
>
> This does everything that I want *except* dynamically adding time to the
> previous macro call.  I tried defining a dynamic version:
>
> #+MACRO: w (eval (format-time-string "Week {{{n(week)}}} (<%Y-%m-%d %a>)"
> (time-add (encode-time 0 0 0 17 9 2017) (days-to-time (* 7 $1 ))
>
> And then calling it with
>
> {{{w({{{n}}})}}}
>
> But unsurprisingly and appropriately, that didn't work.
>
> I also took a look at the patch Nicolas used to implement the {{{n}}}
> macro (I've reattached it here for convenience only!).  It defines
> `org-macro--counter-initialize` and calls it from inside
> `org-macro-templates-initialize`.  I guess I could copy that strategy but
> then I'd be maintaining my own copy of org-macro-templates-initialize,
> which seems like a terrible idea.
>
> So, I'm not sure how best to proceed. For my specific use-case, something
> like this would be a huge timesaver when multiplied over semesters/years.
> But I also wonder whether maybe other people would enjoy being able to do
> date arithmetic inside org files (and outside of tables -- I know from
> Sacha's 2015 blog post  that this is possible inside a table --
> http://sachachua.com/blog/2015/06/using-your-own-emacs-
> lisp-functions-in-org-mode-table-calculations-easier-dosage-totals/).  If
> other people would also use such code, I could try to hack something
> together for submission. Generalizable functions will be hard for me to
> write because I am sometimes a bit dense. I would love to hear suggestions
> from the group...
>
>
>> Thank you everyone!
>>
>
> ^^ this still applies!
> Matt
>
>


Re: [O] [PATCH] org-agenda: Add 'none setting for org-agenda-overriding-header

2017-08-22 Thread Adam Porter
Hi Nicolas,

Nicolas Goaziou  writes:

> Nitpick: the paragraph above usually comes after the list of changes.

Fixed.

> Nitpick: you can only write "Use macro" once, on the last line.

Fixed.

> Why `cl-defmacro'? Usually, `defmacro' is enough.

Fixed.

> While we're at it,
>
>   `org-add-props' + `copy-sequence' = `propertize'
>
> If you're ready for further refactoring, the nested `if' above could
> be turned into a nicer `cond'.
>
> Same here: `mapc' + `lambda' = `dolist' to avoid funcall overhead. `s'
> could be let-bound too.

I'll refactor these in a separate patch to isolate any potential
mistakes.

>> + ;; When nil, make string automatically and insert it
>> + ((pred null) (insert ,default
>
> I suggest to use ,@default (and, obviously (&rest default) in the
> arguments) so we are not limited to one S-exp.

I saw that all of the default header code boiled down to inserting a
string, so I moved the ultimate `insert' into the macro so it could
accept a form that evaluates to a string; it seemed like a cleaner, more
functional approach to essentially accept a string rather than arbitrary
code (even though it does accept any sexp, but that is to avoid
evaluating it unless it's needed).  I used a keyword argument rather
than &rest for two reasons: 1) so the macro could accept different
option arguments in the future, and 2) so it's plain from looking at the
macro call that the form given is the default, which may be overridden,
rather than what's always used.

If you would prefer the &rest approach, that would mean doing the actual
insertion into the agenda buffer in the macro call rather than the macro
expansion.  I thought it would be better to separate the actual
insertion by abstracting it behind the macro.  In fact, it could be done
as a function instead, but, of course, that would mean evaluating the
default even when it's not used, so that's why I chose a macro.  (Or the
default could be passed as a lambda, but that seems even more awkward.)
Anyway, let me know what you prefer.

> All in all, the only requested change is `cl-defmacro' -> `defmacro'.
> This is no blocker if you don't want/have time to do the refactoring.

I'll post a new patch soon.  Thanks.




Re: [O] Bug: export to markdown invalid URL

2017-08-22 Thread Jay Kamat
Hi,

> Isn't it already the case?

Sorry, I sent that email without reading the 'applied' email, so it
was premature. The fix looks good currently.

> I think the current patch is fine. Yours is equivalent, but since we
> already bound `raw-path', we might as well use it.

yup, that is true, I'm happy with the current patch for now, since we
don't have to bind additional variables it ends up being simpler.

Thanks,
-Jay



Re: [O] [PATCH] org-agenda: Add 'none setting for org-agenda-overriding-header

2017-08-22 Thread Adam Porter
Adam Porter  writes:

> I'll post a new patch soon.  Thanks.

Hi Nicolas,

Here are the patches.  Please let me know if any other changes are
needed.

Thanks,
Adam

>From 2b938e98e2cc2409044eb7b03bff98b0a37d404e Mon Sep 17 00:00:00 2001
From: Adam Porter 
Date: Sat, 19 Aug 2017 21:26:12 -0500
Subject: [PATCH 1/2] org-agenda: Refactor org-agenda-overriding-header code

* lisp/org-agenda.el (org-agenda--insert-overriding-header): Add macro.
(org-agenda-list)
(org-search-view)
(org-todo-list)
(org-tags-view): Use macro.
(org-agenda-overriding-header): Update docstring.

* etc/ORG-NEWS: Explain that header can be disabled with empty string.

Replace org-agenda-overriding-header tests in these four functions with
calls to a macro, eliminating the duplicate code.  Also, disable the
header when the variable is set to the empty string.
---
 etc/ORG-NEWS   |   4 ++
 lisp/org-agenda.el | 153 +
 2 files changed, 89 insertions(+), 68 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 1901c29..e55d1e4 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -135,6 +135,10 @@ See docstring for details.
 =org-agenda-tags-column= can now be set to =auto=, which will
 automatically align tags to the right edge of the window.  This is now
 the default setting.
+ Disable =org-agenda-overriding-header= by setting to empty string
+
+The =org-agenda-overriding-header= inserted into agenda views can now be
+disabled by setting it to an empty string.
 
 *** New value for ~org-publish-sitemap-sort-folders~
 
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index fe7c4f2..0cb462e 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2065,6 +2065,22 @@ works you probably want to add it to `org-agenda-custom-commands' for good."
 	(setcdr ass (cdr entry))
   (push entry org-agenda-custom-commands
 
+(defmacro org-agenda--insert-overriding-header (&key default)
+  "Insert header into agenda view depending on value of `org-agenda-overriding-header'.
+If the empty string, don't insert a header.  If any other string,
+insert it as a header.  If nil, insert DEFAULT, which should
+evaluate to a string."
+  (declare (debug (&key form)))
+  `(pcase org-agenda-overriding-header
+ ("" nil)  ; Don't insert a header if set to empty string
+ ;; Insert user-specified string
+ ((pred stringp) (insert
+		  (org-add-props (copy-sequence org-agenda-overriding-header)
+			  nil 'face 'org-agenda-structure)
+		  "\n"))
+ ;; When nil, make string automatically and insert it
+ ((pred null) (insert ,default
+
 ;;; Define the org-agenda-mode
 
 (defvar org-agenda-mode-map (make-sparse-keymap)
@@ -4160,17 +4176,15 @@ items if they have an hour specification like [h]h:mm."
 	   (w1 (org-days-to-iso-week d1))
 	   (w2 (org-days-to-iso-week d2)))
 	  (setq s (point))
-	  (if org-agenda-overriding-header
-	  (insert (org-add-props (copy-sequence org-agenda-overriding-header)
-			  nil 'face 'org-agenda-structure) "\n")
-	(insert (org-agenda-span-name span)
-		"-agenda"
-		(if (< (- d2 d1) 350)
-			(if (= w1 w2)
-			(format " (W%02d)" w1)
-			  (format " (W%02d-W%02d)" w1 w2))
-		  "")
-		":\n")))
+	  (org-agenda--insert-overriding-header
+	   :default (concat (org-agenda-span-name span)
+			"-agenda"
+			(if (< (- d2 d1) 350)
+(if (= w1 w2)
+(format " (W%02d)" w1)
+  (format " (W%02d-W%02d)" w1 w2))
+			  "")
+			":\n")))
 	(add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
 		  'org-date-line t))
 	(org-agenda-mark-header-line s))
@@ -4581,25 +4595,25 @@ in `org-agenda-text-search-extra-files'."
 			(goto-char (1- end))
 	(setq rtn (nreverse ee))
 	(setq rtnall (append rtnall rtn)))
-  (if org-agenda-overriding-header
-	  (insert (org-add-props (copy-sequence org-agenda-overriding-header)
-		  nil 'face 'org-agenda-structure) "\n")
-	(insert "Search words: ")
-	(add-text-properties (point-min) (1- (point))
-			 (list 'face 'org-agenda-structure))
-	(setq pos (point))
-	(insert string "\n")
-	(add-text-properties pos (1- (point)) (list 'face 'org-warning))
-	(setq pos (point))
-	(unless org-agenda-multi
-	  (insert (substitute-command-keys "\
+  (org-agenda--insert-overriding-header
+   :default (with-temp-buffer
+		  (insert "Search words: ")
+		  (add-text-properties (point-min) (1- (point))
+   (list 'face 'org-agenda-structure))
+		  (setq pos (point))
+		  (insert string "\n")
+		  (add-text-properties pos (1- (point)) (list 'face 'org-warning))
+		  (setq pos (point))
+		  (unless org-agenda-multi
+		(insert (substitute-command-keys "\
 Press `\\[org-agenda-manipulate-query-add]', \
 `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
 `\\[org-agenda-manipulate-query-add-re]', \
 `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
 `\\[universal-argument] \\[org-agenda-redo]' to edit\n"))
-	  

Re: [O] dynamic date arithmetic in a macro or otherwise (simulating a "date counter")?

2017-08-22 Thread Adam Porter
I just discovered this yesterday, and it seems relevant:

https://github.com/abo-abo/tiny

Apparently it can be used like this:

m\n8| TODO Learning from Data Week %(+ x 2) \nSCHEDULED: <%(date "Oct 7" (* 
x 7))> DEADLINE: <%(date "Oct 14" (* x 7))>

Which results in:

 TODO Learning from Data Week 2
SCHEDULED: <2013-10-07 Mon> DEADLINE: <2013-10-14 Mon>
 TODO Learning from Data Week 3
SCHEDULED: <2013-10-14 Mon> DEADLINE: <2013-10-21 Mon>
[...]




[O] Capture w/ timestamp does not include current timestamp

2017-08-22 Thread Ken Mankoff
Hi List,

I'm not sure if this is a bug or not - it seems to be, but it has been 
discussed on the list[1] (and elswhere[2]) and not fixed, and I wonder if that 
is because nobody explicitly called it out as a bug. At a minimum, I think it 
is a documentation bug.

A capture template with %^T or %^U will prompt for date and time, but if I hit 
ENTER without manually typing a time, the present time (shown in the prompt) is 
dropped, and only a date is used in the capture.

This is different behavior than, for example =org-time-stamp= or 
=org-time-stamp-inactive= run with a prefix argument (e.g. "C-u C-c C-.").

Without a time prompt (i.e. %^t or %^u), I can still manually enter a time and 
it works. So the only benefit of %^T or %^U is that the current time is 
displayed in the prompt, but I still have to manually type it out? This seems 
inefficient, hence I think this is a bug.

If the behavior is correct, the following doc strings should probably be 
updated:

%t  Time stamp, date only.  The time stamp is the current time,
except when called from agendas with ‘M-x org-agenda-capture’ or
with ‘org-capture-use-agenda-date’ set.
%T  Time stamp as above, with date and time.
%u, %U  Like the above, but inactive time stamps.

Regards,

  Ken Mankoff

Org mode version 9.0.9 (9.0.9-88-g251f88-elpaplus @ 
/Users/mankoff/.emacs.d/elpa/org-plus-contrib-20170821/)

[1] https://lists.gnu.org/archive/html/emacs-orgmode/2016-02/msg00323.html
[2] https://emacs.stackexchange.com/questions/24368/



Re: [O] merging subtrees (in a syllabus)

2017-08-22 Thread Adam Porter
Hi Matt,

One potentially crazy idea would be to store each lab/discussion entry
in a named "#+BEGIN_SRC org" block, and use Babel <> to merge
them in a final noweb SRC block.  Seems a bit recursive, but I guess you
could edit each org block with org-edit-special and escape the nesting.

Another possibility would be to leave them as they are now, but to use
sparse trees in combination with tags or properties to only display lab
or discussion entries.

Also, you may find org-tree-to-indirect-buffer useful.  I have the
impression that not many Org users are aware of it or how
powerful--might I even say, liberating--it is.  You can essentially edit
each subtree of your document as a separate document in its own buffer,
while behind the scenes it's all taking place in the source buffer.  If
you're interested in this, I could provide some more details and some
support functions that make it more useful.

> If it also comes with a thought about how to generate an org date
> objet form an initial seed and a session number, that's be fabulous
> too.

I just discovered this yesterday, and it seems relevant:

https://github.com/abo-abo/tiny

Apparently it can be used like this:

m\n8| TODO Learning from Data Week %(+ x 2) \nSCHEDULED: <%(date "Oct 7" (* 
x 7))> DEADLINE: <%(date "Oct 14" (* x 7))>

Which results in:

 TODO Learning from Data Week 2
SCHEDULED: <2013-10-07 Mon> DEADLINE: <2013-10-14 Mon>
 TODO Learning from Data Week 3
SCHEDULED: <2013-10-14 Mon> DEADLINE: <2013-10-21 Mon>
[...]

Hope this helps!

Adam




Re: [O] counter macro in dates?

2017-08-22 Thread Adam Porter
Matt Price  writes:

> I'd love to be able generate dates dynamically using the {{{n}}} org
> macro, or some other mechanism. I don't immediately see how that would
> be possible but maybe someone can guide me. I'd want to do something
> equivalent to this pseudo-elisp:
>
> (let ((base-date 2017-09-05))
> (+ base-date (* 7 {{{n}}}))
>
> I haven't looked into how date objects are parsed in org-mode, though,
> so I have no idea how hard it would be to actually implement something
> like this.

Apologies to the list for practically spamming this recently, but it
seems directly relevant:

https://github.com/abo-abo/tiny

It has built-in support for Org dates with its %(date) function.
Apparently it can be used like this:

m\n8| TODO Learning from Data Week %(+ x 2) \nSCHEDULED: <%(date "Oct 7" (* 
x 7))> DEADLINE: <%(date "Oct 14" (* x 7))>

Which results in:

 TODO Learning from Data Week 2
SCHEDULED: <2013-10-07 Mon> DEADLINE: <2013-10-14 Mon>
 TODO Learning from Data Week 3
SCHEDULED: <2013-10-14 Mon> DEADLINE: <2013-10-21 Mon>
[...]