Re: [PATCH] Add NO-STATS switch to org-get-heading

2020-03-13 Thread Brice Waegeneire

Hello Nicolas,

On 2020-03-13 17:22, Nicolas Goaziou wrote:

* lisp/org-element.el (org-element-context): Handle headlines only
containing a statistics cookie.
* lisp/org.el (test-org/get-heading): Add regex capture group 6 for
statistics cookie.
(org-get-heading): Add NO-STATS argument, if
non-nil, will not return the statistics cookie.
* testing/lisp/test-org.el (test-org/get-heading): Add 3 tests using 
the

NO-STATS argument.


This assumes statistics cookie is always located at the end of the
title, before the tags. This is not required by the syntax.

Syntax can evolve, but it could introduce many backward
incompatibilities, so it must be discussed first.


I wasn't sure about this. I don't remember ever seeing somebody putting 
the

statistics cookie before the title but org-complex-heading-regexp-format
does support two position for the statistics cookie. Would adding 
support

for the two locations to this patch make the review process faster?

I was just looking for a way to get a heading title without any 
metadata.


Cheers.



[PATCH] Add NO-STATS switch to org-get-heading

2020-03-13 Thread Brice Waegeneire
* lisp/org-element.el (org-element-context): Handle headlines only
containing a statistics cookie.
* lisp/org.el (test-org/get-heading): Add regex capture group 6 for
statistics cookie.
(org-get-heading): Add NO-STATS argument, if
non-nil, will not return the statistics cookie.
* testing/lisp/test-org.el (test-org/get-heading): Add 3 tests using the
NO-STATS argument.
---
 lisp/org-element.el  |  4 ++--
 lisp/org.el  | 13 +
 testing/lisp/test-org.el | 13 +
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 798c540e9..c1798e07a 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -5906,9 +5906,9 @@ Providing it allows for quicker computation."
 (let ((case-fold-search nil))
   (goto-char (org-element-property :begin element))
   (looking-at org-complex-heading-regexp)
-  (let ((end (match-end 4)))
+  (let ((end (or (match-end 6) (match-end 4
 (if (not end) (throw 'objects-forbidden element)
-  (goto-char (match-beginning 4))
+  (goto-char (or (match-beginning 4) (match-beginning 6)))
   (when (looking-at org-comment-string)
 (goto-char (match-end 0)))
   (if (>= (point) end) (throw 'objects-forbidden element)
diff --git a/lisp/org.el b/lisp/org.el
index 31133c554..b6fc6ad26 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4011,6 +4011,7 @@ group 2: The TODO keyword, maybe
 group 3: Priority cookie
 group 4: True headline
 group 5: Tags
+group 6: Statistics cookie
 
 Since TODO keywords are case-sensitive, `case-fold-search' is
 expected to be bound to nil when matching against this regexp.")
@@ -4328,7 +4329,8 @@ related expressions."
  "\\(?: +" org-todo-regexp "\\)?"
  "\\(?: +\\(\\[#.\\]\\)\\)?"
  "\\(?: +\\(.*?\\)\\)??"
- "\\(?:[ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?"
+ "\\(?: +\\(?6:\\[[0-9%%/]+\\]\\)\\)?"
+ "\\(?:[ \t]+\\(?5::[[:alnum:]_@#%:]+:\\)\\)?"
  "[ \t]*$")
  org-complex-heading-regexp-format
  (concat "^\\(\\*+\\)"
@@ -6897,12 +6899,14 @@ So this will delete or add empty lines."
 (insert (make-string n ?\n))
 (move-to-column column)))
 
-(defun org-get-heading ( no-tags no-todo no-priority no-comment)
+(defun org-get-heading ( no-tags no-todo no-priority
+  no-comment no-stats)
   "Return the heading of the current entry, without the stars.
 When NO-TAGS is non-nil, don't include tags.
 When NO-TODO is non-nil, don't include TODO keywords.
 When NO-PRIORITY is non-nil, don't include priority cookie.
 When NO-COMMENT is non-nil, don't include COMMENT string.
+When NO-STATS is non-nil, don't include statistics cookie.
 Return nil before first heading."
   (unless (org-before-first-heading-p)
 (save-excursion
@@ -6919,9 +6923,10 @@ Return nil before first heading."
  (format "\\`%s[ \t]+" org-comment-string))
"" h))
  (h h)))
- (tags (and (not no-tags) (match-string 5
+ (tags (and (not no-tags) (match-string 5)))
+(stats (and (not no-stats) (match-string 6
  (mapconcat #'identity
-(delq nil (list todo priority headline tags))
+(delq nil (list todo priority headline stats tags))
 " "))
 
 (defun org-heading-components ()
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index dc4a6a59f..f98918dae 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1887,6 +1887,19 @@
(equal "TODO [#A] H"
  (org-test-with-temp-text "* TODO [#A] COMMENT H"
(org-get-heading nil nil nil t
+  ;; With NO-STATS, ignore statistics cookie.
+  (should
+   (equal "H"
+ (org-test-with-temp-text "* H [1/3]"
+   (org-get-heading nil nil nil nil t
+  (should
+   (equal "H"
+ (org-test-with-temp-text "* H"
+   (org-get-heading nil nil nil nil t
+  (should
+   (equal "TODO [#A] H"
+ (org-test-with-temp-text "* TODO [#A] H [33%]"
+   (org-get-heading nil nil nil nil t
   ;; On an empty headline, return value is consistent.
   (should (equal "" (org-test-with-temp-text "* " (org-get-heading
   (should (equal "" (org-test-with-temp-text "* " (org-get-heading t
-- 
2.25.0




Re: [O] Error after moving from 7.9.4 to 8.0: Cannot open load file org-element

2013-04-23 Thread Brice Waegeneire
Hello,

I have did the same process with the same type of configuration but
with the minimal requirement to install org-mode. Unfortunately I keep
stumbling on the same error, when I reload my configuration (after an
edit) with org-mode 8.0, which is not the case with org-mode 7.9.4.
It looks like org-babel didn't process my org configuration file in a
emacs-lisp file.

The configuration is here :
;;; init.el
;;
;; This is the first thing to get loaded.
;;
(add-to-list 'load-path ~/.emacs.d/el-get/org-mode/contrib/lisp)
(add-to-list 'load-path ~/.emacs.d/el-get/org-mode/lisp)

(require 'org)
(org-babel-load-file ~/.emacs.d/ldk-emacs.org)

;;; init.el ends here

;;; ldk-emacs.el
;;
;; Emacs configuration
;;
* el-get
** Auto-install el-get
If el-get is not installed it will be in the next start

#+begin_src emacs-lisp
(add-to-list 'load-path ~/.emacs.d/el-get/el-get)

(unless (require 'el-get nil 'noerror)
  (with-current-buffer
  (url-retrieve-synchronously
   https://raw.github.com/dimitri/el-get/master/el-get-install.el;)
(goto-char (point-max))
(eval-print-last-sexp)))

(setq el-get-dir ~/.emacs.d/el-get)
(setq el-get-install-dir ~/.emacs.d/el-get/el-get)
#+end_src

** Recipes
*** org-mode
#+BEGIN_SRC emacs-lisp
(add-to-list
 'el-get-sources
 '(:name org-mode
 :checkout release_8.0))
#+END_SRC

** Initalized package
List of packages which are installed and initialized by el-get.

#+begin_src emacs-lisp
  (setq my-packages
'(el-get
  org-mode
  ))

  (el-get 'sync my-packages)
#+end_src

;;; ldk-emacs.el ends here


Can someone help me with this or orient me to do a better report ?

Thanks.


2013/4/21 Brice Waegeneire liberd...@gmail.com:
 Hello org-mode users,

 In moving from 7.9.4 to 8.0 org-mode I stumbled upon the following
 error (emacs --debug-init). The [...] is a portion i couldn't copy:

 Debugger entered--Lisp error: (file-error Cannot open load file
 org-mode/lisp/org-element)
 org-element-at-point()
 org-store-link(nil)
 org-babel-tangle-single-block(1)
 org-babel-tangle-collect-blocks(emacs-lisp nil)
 org-babel-tangle(nil ~/.emacs.d/ldk-emacs.el emacs-lisp)
 org-babel-tangle-file(~/.emacs.d/ldk-emacs.org
 ~/.emacs.d/ldk-emacs.el emacs-lisp)
 org-babel-load-file(~/.emacs.d/ldk-emacs.org)
 eval-buffer(#buffer *load* nil /home/lambda/.emacs.d/init.el nil
 t) ; Reading at buffer position 397
 load-with-code-conversion(/home/lambda/.emacs.d/init.el
 /home/lambda/.emacs.d/init.el t t)
 load(/home/lambda/.emacs.d/init t t)
 #[0  \205\262

 [...]

 [init-file-user system-type delayed-warnings-list user-init-file
 inhibit-default-init inhibit-startup-screen ms-dos ~ /_emacs
 windows-nt /.emacs directory-files nil ^\\.emacs\\(\\.elc?\\)?$
 ~/.emacs ^_emacs\\(\\.elc?\\)?$ (initialization `_emacs' init
 file is deprecated, please use `.emacs') ~/_emacs t load
 expand-file-name init file-name-as-directory /.emacs.d
 file-name-extension elc file-name-sans-extension .el file-exists-p
 file-newer-than-file-p message Warning: %s is newer than %s sit-for
 1 default] 7 \n\n(fn)]()
 command-line()
 normal-top-level()

 For the upgrade I've deleted the org-mode folder, replaced in my emacs
 configuration file release_7.9.4 by release_8.0 and then restarted
 emacs. el-get had then installed org-mode 8.0, after that I don't have
 the issue yet but it occurs after I had modified my emacs'
 configurartion  (whatever the modification) and restarted it.

 You can find my emacs configuration here :
 https://gist.github.com/korthaerd/27877114462e2475f82e#file-emacs-debug-init-8-0

 Can some help me with that ?

 Coridally, liberdiko.



[O] Error after moving from 7.9.4 to 8.0: Cannot open load file org-element

2013-04-21 Thread Brice Waegeneire
Hello org-mode users,

In moving from 7.9.4 to 8.0 org-mode I stumbled upon the following
error (emacs --debug-init). The [...] is a portion i couldn't copy:

Debugger entered--Lisp error: (file-error Cannot open load file
org-mode/lisp/org-element)
org-element-at-point()
org-store-link(nil)
org-babel-tangle-single-block(1)
org-babel-tangle-collect-blocks(emacs-lisp nil)
org-babel-tangle(nil ~/.emacs.d/ldk-emacs.el emacs-lisp)
org-babel-tangle-file(~/.emacs.d/ldk-emacs.org
~/.emacs.d/ldk-emacs.el emacs-lisp)
org-babel-load-file(~/.emacs.d/ldk-emacs.org)
eval-buffer(#buffer *load* nil /home/lambda/.emacs.d/init.el nil
t) ; Reading at buffer position 397
load-with-code-conversion(/home/lambda/.emacs.d/init.el
/home/lambda/.emacs.d/init.el t t)
load(/home/lambda/.emacs.d/init t t)
#[0  \205\262

[...]

[init-file-user system-type delayed-warnings-list user-init-file
inhibit-default-init inhibit-startup-screen ms-dos ~ /_emacs
windows-nt /.emacs directory-files nil ^\\.emacs\\(\\.elc?\\)?$
~/.emacs ^_emacs\\(\\.elc?\\)?$ (initialization `_emacs' init
file is deprecated, please use `.emacs') ~/_emacs t load
expand-file-name init file-name-as-directory /.emacs.d
file-name-extension elc file-name-sans-extension .el file-exists-p
file-newer-than-file-p message Warning: %s is newer than %s sit-for
1 default] 7 \n\n(fn)]()
command-line()
normal-top-level()

For the upgrade I've deleted the org-mode folder, replaced in my emacs
configuration file release_7.9.4 by release_8.0 and then restarted
emacs. el-get had then installed org-mode 8.0, after that I don't have
the issue yet but it occurs after I had modified my emacs'
configurartion  (whatever the modification) and restarted it.

You can find my emacs configuration here :
https://gist.github.com/korthaerd/27877114462e2475f82e#file-emacs-debug-init-8-0

Can some help me with that ?

Coridally, liberdiko.