Re: [O] Bug: org-2ft and/or float-time is wrong [9.1.2 (9.1.2-22-ga2a034-elpaplus @ ~/.emacs.d/elpa/org-plus-contrib-20171023/)]

2017-10-30 Thread Allen Li
On Mon, Oct 30, 2017 at 5:40 PM, Allen Li  wrote:
> (current-time-string (time-to-seconds (org-2ft "<2017-10-31>")))
> "Sun Oct 29 17:00:00 2017"
>
> This seems wrong
>
> In org-2ft
>
> (org-parse-time-string s nil t)
>
> The t means use UTC instead of Emacs local time.
>
> However, Org translates  into (float-time), which is in Emacs localtime.
>
> 1. SCHEDULED>"" compares a UTC time against a local time.
> 2. Either org-2ft should be fixed to be localtime, or  should be
> (float-time) in UTC.
>
> I don't know how Org internals works, but my experience so far has
> been that Emacs and *nix in general is very naive about timezones; a
> naked timestamp is assumed to be localtime if it does not have
> accompanying timezone information.
>
> Thus, it seems to be more correct to change org-2ft to parse times as
> localtime.  However, I don't know if UTC timestamps are assumed by
> other parts of Org internals, in which case fixing  (float-time)
> would be safest.

My initial analysis was wrong because I wasn't thinking clearly.

Just to set a stake in the ground: timestamps are seconds since epoch
and timezone neutral.  Emacs time values are also timezone neutral:
(sec-high sec-low microsec picosec)

(current-time-string (float-time))
"Mon Oct 30 21:21:31 2017" ; right

(current-time-string (org-time-today))
"Mon Oct 30 00:00:00 2017" ; right

(current-time-string (org-2ft "<2017-10-31>"))
"Mon Oct 30 17:00:00 2017" ; wrong

Removing the t for zone fixes it

(defun org-2ft (s)
  "Convert S to a floating point time.
If S is already a number, just return it.  If it is a string, parse
it as a time string and apply `float-time' to it.  If S is nil, just return 0."
  (cond
   ((numberp s) s)
   ((stringp s)
(condition-case nil
(float-time (apply #'encode-time (org-parse-time-string s)))
  (error 0.)))
   (t 0.)))

(current-time-string (org-2ft "<2017-10-31>"))
"Tue Oct 31 00:00:00 2017" ; now right

I will also note that the FIXME comment in org-parse-time-string
suggests that it too is not handling timezones correctly.  In fact,
perhaps org-parse-time-string should not take a zone argument, since
Org does not support timezones thus the only valid value for zone is
nil.  I suspect that org-display-custom-time, another caller that
passes t for zone, is also timezone incorrect.

That is to say, nothing in Org allows passing in a custom timezone,
let alone a UTC timezone; thus, every caller that passes a non-nil
zone to org-parse-time-string is getting an incorrect result.

tl;dr time is hard.



[O] Bug: org-2ft and/or float-time is wrong [9.1.2 (9.1.2-22-ga2a034-elpaplus @ ~/.emacs.d/elpa/org-plus-contrib-20171023/)]

2017-10-30 Thread Allen Li
(current-time-string (time-to-seconds (org-2ft "<2017-10-31>")))
"Sun Oct 29 17:00:00 2017"

This seems wrong

In org-2ft

(org-parse-time-string s nil t)

The t means use UTC instead of Emacs local time.

However, Org translates  into (float-time), which is in Emacs localtime.

1. SCHEDULED>"" compares a UTC time against a local time.
2. Either org-2ft should be fixed to be localtime, or  should be
(float-time) in UTC.

I don't know how Org internals works, but my experience so far has
been that Emacs and *nix in general is very naive about timezones; a
naked timestamp is assumed to be localtime if it does not have
accompanying timezone information.

Thus, it seems to be more correct to change org-2ft to parse times as
localtime.  However, I don't know if UTC timestamps are assumed by
other parts of Org internals, in which case fixing  (float-time)
would be safest.



[O] org-display-inline-images not displaying images

2017-10-30 Thread Leslie Watter
Hi folks,

Does the org-display-inline-images behavior was changed from 9.0.10 up ?

I'm facing some trouble with it -- from 9.0.10 up images are'nt being
displayed .

Same configuration, the only change was org-version.

How I'm calling:

--
#+CAPTION: Criando novo Projeto Maven
#+LABEL:
[[./images/git/eclipse/l/novo-projeto-maven.png]]
--

One weird thing is that, if I generate the image using a ditaa source code,
this image got displayed correctly, but the others dont. Both are PNG
files.

Does anyone has any hint ?

Thanks in advance,

LEslie


-- 
Leslie H. Watter


Re: [O] function for inserting a block

2017-10-30 Thread Eric Abrahamsen
Sorry, last patch had some documentation errors.

>From 055af9e9545947b9aeccc3370c8b67a237eea5d8 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen 
Date: Mon, 30 Oct 2017 10:55:29 -0700
Subject: [PATCH] Replace easy templates with org-insert-structure-template

* lisp/org.el (org-insert-structure-template): New function for
  wrapping region (or element at point) in a begin/end block.
  (org-structure-predefined-blocks): New option holding predefined
  blocks, for completion.
  (org-try-structure-completion,
  org-complete-expand-structure-template): Remove functions.
* doc/org.texi (Inserting structure templates): Document.
* testing/lisp/test-org.el (test-org/insert-template): New test.
---
 doc/org.texi | 756 +++
 etc/ORG-NEWS |   4 +
 lisp/org.el  | 132 -
 testing/lisp/test-org.el |  46 +++
 4 files changed, 491 insertions(+), 447 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 77da6d335..486fe88fe 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -652,7 +652,7 @@ Texinfo export
 * Texinfo specific export settings::  Setting the environment.
 * Texinfo file header:: Generating the header.
 * Texinfo title and copyright page::  Creating preamble pages.
-* Info directory file:: Installing a manual in Info file hierarchy.
+* Info directory file:: Installing a manual in Info file hierarchy.
 * Headings and sectioning structure::  Building document structure.
 * Indices:: Creating indices.
 * Quoting Texinfo code::Incorporating literal Texinfo code.
@@ -749,7 +749,7 @@ Specific header arguments
 Miscellaneous
 
 * Completion::  M-TAB guesses completions
-* Easy templates::  Quick insertion of structural elements
+* Inserting structure templates::  Wrapping text in code blocks
 * Speed keys::  Electric commands at the beginning of a headline
 * Code evaluation security::Org mode files evaluate inline code
 * Customization::   Adapting Org to changing tastes
@@ -796,7 +796,7 @@ MobileOrg
 @end detailmenu
 @end menu
 
-@node Introduction
+@node Introduction, Document structure, Top, Top
 @chapter Introduction
 @cindex introduction
 
@@ -808,7 +808,7 @@ MobileOrg
 * Conventions:: Typesetting conventions in the manual
 @end menu
 
-@node Summary
+@node Summary, Installation, Introduction, Introduction
 @section Summary
 @cindex summary
 
@@ -864,7 +864,7 @@ Network Theory Ltd.}
 
 @page
 
-@node Installation
+@node Installation, Activation, Summary, Introduction
 @section Installation
 @cindex installation
 
@@ -940,7 +940,7 @@ For more detailed explanations on Org's build system, please check the Org
 Build System page on @uref{http://orgmode.org/worg/dev/org-build-system.html,
 Worg}.
 
-@node Activation
+@node Activation, Feedback, Installation, Introduction
 @section Activation
 @cindex activation
 @cindex autoload
@@ -991,7 +991,7 @@ the default.  If you do not like @code{transient-mark-mode}, you can create
 an active region by using the mouse to select a region, or pressing
 @kbd{C-@key{SPC}} twice before moving the cursor.
 
-@node Feedback
+@node Feedback, Conventions, Activation, Introduction
 @section Feedback
 @cindex feedback
 @cindex bug reports
@@ -1091,7 +1091,7 @@ screen.  Save this buffer to a file (for example using @kbd{C-x C-w}) and
 attach it to your bug report.
 @end enumerate
 
-@node Conventions
+@node Conventions,  , Feedback, Introduction
 @section Typesetting conventions used in this manual
 
 @subsubheading TODO keywords, tags, properties, etc.
@@ -1141,7 +1141,7 @@ will be listed to call @code{org-table-move-column-right}.  If you prefer,
 you can compile the manual without the command names by unsetting the flag
 @code{cmdnames} in @file{org.texi}.
 
-@node Document structure
+@node Document structure, Tables, Introduction, Top
 @chapter Document structure
 @cindex document structure
 @cindex structure of document
@@ -1164,7 +1164,7 @@ edit the structure of the document.
 * Org syntax::  Formal description of Org's syntax
 @end menu
 
-@node Outlines
+@node Outlines, Headlines, Document structure, Document structure
 @section Outlines
 @cindex outlines
 @cindex Outline mode
@@ -1178,7 +1178,7 @@ currently being worked on.  Org greatly simplifies the use of
 outlines by compressing the entire show/hide functionality into a single
 command, @command{org-cycle}, which is bound to the @key{TAB} key.
 
-@node Headlines
+@node Headlines, Visibility cycling, Outlines, Document structure
 @section Headlines
 @cindex headlines
 @cindex outline tree
@@ -1220,7 +1220,7 @@ least two empty lines, one empty line will remain visible after folding
 the subtree, in order to structure the collapsed view.  See the
 variable @code{org-cycle-separator-lines} to modify this behavior.
 
-@node Visibility cycling
+@node Visibility cycling, Motion, 

[O] tangle and comments.

2017-10-30 Thread Uwe Brauer


Hi

I followed the instructions found in
http://eschulte.github.io/babel-dev/DONE-tangle-entire-org-mode-file-in-comments.html

Although they are 7 years old however when I try to tangle the example
file I receive

Tangled 0 code blocks from tangle2.org

Here is the file just in case


Uwe Brauer 
 tangling with yes or link comments
   :PROPERTIES:
   :comments: yes
   :tangle:   comments.el
   :END:
The top block
#+begin_src emacs-lisp
  (message "first block")
#+end_src

here's some text which won't be tangled

* subheading
another block
| 1 | first  |
| 2 | second |
#+source: tangle-el-the-second
#+begin_src emacs-lisp
  (message "second")
#+end_src

and finally a block with a =:noweb= header argument
#+begin_src emacs-lisp :noweb yes
  (progn
<>)
#+end_src




[O] Get rid of message-mode code?

2017-10-30 Thread Eric Abrahamsen
Now that orgstruct-mode is gone, can't we get rid of all the checks for
message-mode when filling, etc?

diff --git a/lisp/org.el b/lisp/org.el
index 9ad06ac3b..ed338ad80 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -22316,68 +22316,58 @@ assumed to be significant there."
 Return fill prefix, as a string, or nil if current line isn't
 meant to be filled.  For convenience, if `adaptive-fill-regexp'
 matches in paragraphs or comments, use it."
-  (catch 'exit
-(when (derived-mode-p 'message-mode)
-  (save-excursion
-	(beginning-of-line)
-	(cond ((not (message-in-body-p)) (throw 'exit nil))
-	  ((looking-at-p org-table-line-regexp) (throw 'exit nil))
-	  ((looking-at message-cite-prefix-regexp)
-	   (throw 'exit (match-string-no-properties 0)))
-	  ((looking-at org-outline-regexp)
-	   (throw 'exit (make-string (length (match-string 0)) ?\s))
-(org-with-wide-buffer
- (unless (org-at-heading-p)
-   (let* ((p (line-beginning-position))
-	  (element (save-excursion
-			 (beginning-of-line)
-			 (org-element-at-point)))
-	  (type (org-element-type element))
-	  (post-affiliated (org-element-property :post-affiliated element)))
-	 (unless (< p post-affiliated)
-	   (cl-case type
-	 (comment
+  (org-with-wide-buffer
+   (unless (org-at-heading-p)
+ (let* ((p (line-beginning-position))
+	(element (save-excursion
+		   (beginning-of-line)
+		   (org-element-at-point)))
+	(type (org-element-type element))
+	(post-affiliated (org-element-property :post-affiliated element)))
+   (unless (< p post-affiliated)
+	 (cl-case type
+	   (comment
+	(save-excursion
+	  (beginning-of-line)
+	  (looking-at "[ \t]*")
+	  (concat (match-string 0) "# ")))
+	   (footnote-definition "")
+	   ((item plain-list)
+	(make-string (org-list-item-body-column post-affiliated) ?\s))
+	   (paragraph
+	;; Fill prefix is usually the same as the current line,
+	;; unless the paragraph is at the beginning of an item.
+	(let ((parent (org-element-property :parent element)))
 	  (save-excursion
 		(beginning-of-line)
-		(looking-at "[ \t]*")
-		(concat (match-string 0) "# ")))
-	 (footnote-definition "")
-	 ((item plain-list)
-	  (make-string (org-list-item-body-column post-affiliated) ?\s))
-	 (paragraph
-	  ;; Fill prefix is usually the same as the current line,
-	  ;; unless the paragraph is at the beginning of an item.
-	  (let ((parent (org-element-property :parent element)))
-		(save-excursion
-		  (beginning-of-line)
-		  (cond ((eq (org-element-type parent) 'item)
-			 (make-string (org-list-item-body-column
-   (org-element-property :begin parent))
-  ?\s))
-			((and adaptive-fill-regexp
-			  ;; Locally disable
-			  ;; `adaptive-fill-function' to let
-			  ;; `fill-context-prefix' handle
-			  ;; `adaptive-fill-regexp' variable.
-			  (let (adaptive-fill-function)
-(fill-context-prefix
- post-affiliated
- (org-element-property :end element)
-			((looking-at "[ \t]+") (match-string 0))
-			(t  "")
-	 (comment-block
-	  ;; Only fill contents if P is within block boundaries.
-	  (let* ((cbeg (save-excursion (goto-char post-affiliated)
-	   (forward-line)
-	   (point)))
-		 (cend (save-excursion
-			 (goto-char (org-element-property :end element))
-			 (skip-chars-backward " \r\t\n")
-			 (line-beginning-position
-		(when (and (>= p cbeg) (< p cend))
-		  (if (save-excursion (beginning-of-line) (looking-at "[ \t]+"))
-		  (match-string 0)
-		"")))
+		(cond ((eq (org-element-type parent) 'item)
+		   (make-string (org-list-item-body-column
+ (org-element-property :begin parent))
+?\s))
+		  ((and adaptive-fill-regexp
+			;; Locally disable
+			;; `adaptive-fill-function' to let
+			;; `fill-context-prefix' handle
+			;; `adaptive-fill-regexp' variable.
+			(let (adaptive-fill-function)
+			  (fill-context-prefix
+			   post-affiliated
+			   (org-element-property :end element)
+		  ((looking-at "[ \t]+") (match-string 0))
+		  (t  "")
+	   (comment-block
+	;; Only fill contents if P is within block boundaries.
+	(let* ((cbeg (save-excursion (goto-char post-affiliated)
+	 (forward-line)
+	 (point)))
+		   (cend (save-excursion
+			   (goto-char (org-element-property :end element))
+			   (skip-chars-backward " \r\t\n")
+			   (line-beginning-position
+	  (when (and (>= p cbeg) (< p cend))
+		(if (save-excursion (beginning-of-line) (looking-at "[ \t]+"))
+		(match-string 0)
+		  ""))
 
 (declare-function message-goto-body "message" ())
 (defvar message-cite-prefix-regexp)	; From message.el
@@ -22422,15 +22412,6 @@ a footnote definition, try to fill the first paragraph within."
 			 (org-element-property :contents-end element
 	   ;; Do nothing if point is at an affiliated 

Re: [O] function for inserting a block

2017-10-30 Thread Eric Abrahamsen
Nicolas Goaziou  writes:

> Hello,
>
> Eric Abrahamsen  writes:
>
>> This will get there eventually! Because there's likely to be more
>> tweaking, I haven't touched the manual or the tests yet, just reworked
>> the option and function:
>
> Thank you. Some comments follow.
>
>> #+BEGIN_SRC elisp
>> (defcustom org-structure-template-alist
>>   '((?s . "SRC")
>> (?e . "EXAMPLE")
>> (?E . "EXPORT")
>> (?q . "QUOTE")
>> (?v . "VERSE")
>> (?V . "VERBATIM")
>
> This block type doesn't exist. You can remove it.
>
>> (?c . "CENTER")
>> (?C . "COMMENT")
>> (?l . "EXPORT latex")
>> (?L . "#+LaTeX")
>
> #+LATEX or #+latex (see below)
>
>> (?h . "EXPORT html")
>> (?H . "#+HTML")
>> (?a . "EXPORT ascii")
>> (?A . "#+ASCII")
>> (?i . "#+INDEX")
>> (?I . "#+INCLUDE"))
>
> As suggested by Rasmus once, maybe we could get away from FORTRAN touch
> and insert everything lowercase.

Sounds good to me.

>>   "Structure completion elements.
>> This is an alist of characters and values.  When
>> `org-insert-structure-template' is called, an additional key is
>> read.  The key is first looked up in this alist, and the
>> corresponding structure is inserted.  Hitting  will prompt
>> for a structure.
>
> I would remove "Hitting  prompts for a structure." which belongs to
> the function's docstring, not to variable's.
>
>> Structure strings prefixed with a \"#+\" are inserted with no
>> further processing.  Strings without this prefix are used to
>> create a block structure, with \"#+BEGIN\" and \"#+END\" added
>> automatically.
>
> I'm not sure about this part. I understand the backward-compatibility
> concern, but it sounds a bit alien to the purpose of the function, i.e.,
> there is no wrapping around, it is not an "environment" either. WDYT?

It was a hack; I was trying to make the smallest change possible. But
that does turn it into a bit of a Frankenstein, and I would prefer to
remove it. As you mentioned earlier, Emacs already has mechanism for
inserting snippets.

The "include" case is a little different, since it does provide some
extra convenience. I've still taken it out in the next version below, though.

>> WHAT TO DO ABOUT THIS PART?
>> There are two templates for each key, the first uses the original Org
>> syntax,
>
> You can remove it.
>
>> the second uses Emacs Muse-like syntax tags.  These Muse-like tags become
>> the default when the /org-mtags.el/ module has been loaded.  See also the
>> variable `org-mtags-prefer-muse-templates'."
>>   :group 'org-completion
>>   :type '(repeat
>>(cons
>> (character :tag "Key")
>> (string :tag "Template")))
>>   :version "26.1"
>>   :package-version '(Org . "8.3"))
>
> You need to update :version and :package-version. Technically,
> if :package-version is provided, we should only use it, IIUC.

I've never really understood the difference. Current version is 9.1.2,
will this function be present in 9.1.3, or 9.2.0? I've assumed 9.2.0 in
the next version of the patch.

>> (defun org-insert-structure-template ( type)
>>   "Insert a block structure of the type #+BEGIN_FOO/#+END_FOO.
>> This function first reads a character, which can be one of the
>> keys in `org-structure-template-alist'.  It can also be , in
>> which case the user is prompted for a string to use.
>
> "When it is , prompt the user for a string to use."
>
>>   (interactive)
>>   (let* ((key (read-key "Key: "))
>>   (struct-string
>>(or (cdr-safe (assq key org-structure-template-alist))
>
> `cdr-safe' -> `cdr'
>
>>(when (= key ?\t)
>>  (read-string "Structure type: "))
>
> Nitpick: (and (eq key ?\t) (read-string ...))

Out of curiosity is this a style thing, or semantics, or performance?

>>(error "'%c' has no structure definition" key
>> (if (string-prefix-p "#+" struct-string)
>>  (progn
>>(insert (format "%s: " struct-string))
>>(when (string= "#+INCLUDE" struct-string)
>>  (insert
>>   (format "\"%s\""
>>   (abbreviate-file-name
>>(read-file-name "Include file: "))
>

If we take out special handling of "#+" strings, this part is gone
anyway.

Here's a new version with all the above changes made, and the docs
tweaked accordingly.

>From 086733d275ebfb10726144e92ccd30be605c5516 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen 
Date: Mon, 30 Oct 2017 09:19:15 -0700
Subject: [PATCH] Replacing easy templates with function
 org-insert-structure-template

* lisp/org.el (org-insert-structure-template): New function for
  wrapping region (or element at point) in a begin/end block.
  (org-structure-predefined-blocks): New option holding predefined
  blocks, for completion.
  (org-try-structure-completion,
  org-complete-expand-structure-template): Remove functions.
* doc/org.texi (Inserting structure templates): Document.
* 

Re: [O] function for inserting a block

2017-10-30 Thread Eric S Fraga
On Monday, 30 Oct 2017 at 12:05, Nicolas Goaziou wrote:

[...]

> As suggested by Rasmus once, maybe we could get away from FORTRAN touch
> and insert everything lowercase.

+1 (repeat many times)

-- 
: Eric S Fraga via Emacs 27.0.50, Org release_9.1.2-155-gf474c7


signature.asc
Description: PGP signature


Re: [O] function for inserting a block

2017-10-30 Thread Nicolas Goaziou
Hello,

Eric Abrahamsen  writes:

> This will get there eventually! Because there's likely to be more
> tweaking, I haven't touched the manual or the tests yet, just reworked
> the option and function:

Thank you. Some comments follow.

> #+BEGIN_SRC elisp
> (defcustom org-structure-template-alist
>   '((?s . "SRC")
> (?e . "EXAMPLE")
> (?E . "EXPORT")
> (?q . "QUOTE")
> (?v . "VERSE")
> (?V . "VERBATIM")

This block type doesn't exist. You can remove it.

> (?c . "CENTER")
> (?C . "COMMENT")
> (?l . "EXPORT latex")
> (?L . "#+LaTeX")

#+LATEX or #+latex (see below)

> (?h . "EXPORT html")
> (?H . "#+HTML")
> (?a . "EXPORT ascii")
> (?A . "#+ASCII")
> (?i . "#+INDEX")
> (?I . "#+INCLUDE"))

As suggested by Rasmus once, maybe we could get away from FORTRAN touch
and insert everything lowercase.

>   "Structure completion elements.
> This is an alist of characters and values.  When
> `org-insert-structure-template' is called, an additional key is
> read.  The key is first looked up in this alist, and the
> corresponding structure is inserted.  Hitting  will prompt
> for a structure.

I would remove "Hitting  prompts for a structure." which belongs to
the function's docstring, not to variable's.

> Structure strings prefixed with a \"#+\" are inserted with no
> further processing.  Strings without this prefix are used to
> create a block structure, with \"#+BEGIN\" and \"#+END\" added
> automatically.

I'm not sure about this part. I understand the backward-compatibility
concern, but it sounds a bit alien to the purpose of the function, i.e.,
there is no wrapping around, it is not an "environment" either. WDYT?

> WHAT TO DO ABOUT THIS PART?
> There are two templates for each key, the first uses the original Org
> syntax,

You can remove it.

> the second uses Emacs Muse-like syntax tags.  These Muse-like tags become
> the default when the /org-mtags.el/ module has been loaded.  See also the
> variable `org-mtags-prefer-muse-templates'."
>   :group 'org-completion
>   :type '(repeat
> (cons
>  (character :tag "Key")
>  (string :tag "Template")))
>   :version "26.1"
>   :package-version '(Org . "8.3"))

You need to update :version and :package-version. Technically,
if :package-version is provided, we should only use it, IIUC.

> (defun org-insert-structure-template ( type)
>   "Insert a block structure of the type #+BEGIN_FOO/#+END_FOO.
> This function first reads a character, which can be one of the
> keys in `org-structure-template-alist'.  It can also be , in
> which case the user is prompted for a string to use.  

"When it is , prompt the user for a string to use."

>   (interactive)
>   (let* ((key (read-key "Key: "))
>(struct-string
> (or (cdr-safe (assq key org-structure-template-alist))

`cdr-safe' -> `cdr'

> (when (= key ?\t)
>   (read-string "Structure type: "))

Nitpick: (and (eq key ?\t) (read-string ...))

> (error "'%c' has no structure definition" key
> (if (string-prefix-p "#+" struct-string)
>   (progn
> (insert (format "%s: " struct-string))
> (when (string= "#+INCLUDE" struct-string)
>   (insert
>(format "\"%s\""
>(abbreviate-file-name
> (read-file-name "Include file: "))

See above.


Regards,

-- 
Nicolas Goaziou



[O] "Body" of current section

2017-10-30 Thread Richard Parsons
Hello

I can use org-element-at-point to get information about the current
section. What function do I run in order to get its "body" i.e. ignoring
the header and the properties drawer?

Many thanks
Richard