]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-list.el
Simplify now that float-time etc. are built-in
[gnu-emacs] / lisp / org / org-list.el
index 92a92491e3056cdf73c01e576ac08105d013bde7..e119fbf3542021838f72b5c25bff81d3024a7558 100644 (file)
@@ -1,6 +1,6 @@
 ;;; org-list.el --- Plain lists for Org-mode
 ;;
 ;;; org-list.el --- Plain lists for Org-mode
 ;;
-;; Copyright (C) 2004-2014 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2016 Free Software Foundation, Inc.
 ;;
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;;        Bastien Guerry <bzg@gnu.org>
 ;;
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;;        Bastien Guerry <bzg@gnu.org>
@@ -174,7 +174,7 @@ to the bullet that should be used when this item is demoted.
 For example,
 
  (setq org-list-demote-modify-bullet
 For example,
 
  (setq org-list-demote-modify-bullet
-       '((\"+\" . \"-\") (\"-\" . \"+\") (\"*\" . \"+\")))
+       \\='((\"+\" . \"-\") (\"-\" . \"+\") (\"*\" . \"+\")))
 
 will make
 
 
 will make
 
@@ -230,7 +230,7 @@ This variable needs to be set before org.el is loaded.  If you
 need to make a change while Emacs is running, use the customize
 interface or run the following code after updating it:
 
 need to make a change while Emacs is running, use the customize
 interface or run the following code after updating it:
 
-  \(when (featurep 'org-element) (load \"org-element\" t t))"
+  (when (featurep \\='org-element) (load \"org-element\" t t))"
   :group 'org-plain-lists
   :version "24.1"
   :type 'boolean
   :group 'org-plain-lists
   :version "24.1"
   :type 'boolean
@@ -431,7 +431,7 @@ group 4: description tag")
           (context (org-list-context))
           (lim-up (car context))
           (drawers-re (concat "^[ \t]*:\\("
           (context (org-list-context))
           (lim-up (car context))
           (drawers-re (concat "^[ \t]*:\\("
-                              (mapconcat 'regexp-quote org-drawers "\\|")
+                              (mapconcat #'regexp-quote org-drawers "\\|")
                               "\\):[ \t]*$"))
           (inlinetask-re (and (featurep 'org-inlinetask)
                               (org-inlinetask-outline-regexp)))
                               "\\):[ \t]*$"))
           (inlinetask-re (and (featurep 'org-inlinetask)
                               (org-inlinetask-outline-regexp)))
@@ -550,7 +550,7 @@ Contexts `block' and `invalid' refer to `org-list-forbidden-blocks'."
               ;; Can't use org-drawers-regexp as this function might
               ;; be called in buffers not in Org mode.
               (beg-re (concat "^[ \t]*:\\("
               ;; Can't use org-drawers-regexp as this function might
               ;; be called in buffers not in Org mode.
               (beg-re (concat "^[ \t]*:\\("
-                              (mapconcat 'regexp-quote org-drawers "\\|")
+                              (mapconcat #'regexp-quote org-drawers "\\|")
                               "\\):[ \t]*$")))
           (when (save-excursion
                   (and (not (looking-at beg-re))
                               "\\):[ \t]*$")))
           (when (save-excursion
                   (and (not (looking-at beg-re))
@@ -620,11 +620,11 @@ point-at-bol:
 
 will get the following structure:
 
 
 will get the following structure:
 
-\(\(1 0 \"- \"  nil \"[X]\" nil 97\)
\(18 2 \"1. \"  nil nil nil 34\)
\(34 2 \"5. \" \"5\" nil nil 55\)
\(97 0 \"- \"  nil nil nil 131\)
\(109 2 \"+ \" nil nil \"tag\" 131\)
+ ((1 0 \"- \"  nil \"[X]\" nil 97)
 (18 2 \"1. \"  nil nil nil 34)
 (34 2 \"5. \" \"5\" nil nil 55)
 (97 0 \"- \"  nil nil nil 131)
 (109 2 \"+ \" nil nil \"tag\" 131))
 
 Assume point is at an item."
   (save-excursion
 
 Assume point is at an item."
   (save-excursion
@@ -636,12 +636,12 @@ Assume point is at an item."
           (text-min-ind 10000)
           (item-re (org-item-re))
           (drawers-re (concat "^[ \t]*:\\("
           (text-min-ind 10000)
           (item-re (org-item-re))
           (drawers-re (concat "^[ \t]*:\\("
-                              (mapconcat 'regexp-quote org-drawers "\\|")
+                              (mapconcat #'regexp-quote org-drawers "\\|")
                               "\\):[ \t]*$"))
           (inlinetask-re (and (featurep 'org-inlinetask)
                               (org-inlinetask-outline-regexp)))
           (beg-cell (cons (point) (org-get-indentation)))
                               "\\):[ \t]*$"))
           (inlinetask-re (and (featurep 'org-inlinetask)
                               (org-inlinetask-outline-regexp)))
           (beg-cell (cons (point) (org-get-indentation)))
-          ind itm-lst itm-lst-2 end-lst end-lst-2 struct
+           itm-lst itm-lst-2 end-lst end-lst-2 struct
           (assoc-at-point
            (function
             ;; Return association at point.
           (assoc-at-point
            (function
             ;; Return association at point.
@@ -926,13 +926,13 @@ Value returned is the position of the first child of ITEM."
               (< ind (org-list-get-ind child-maybe struct)))
       child-maybe)))
 
               (< ind (org-list-get-ind child-maybe struct)))
       child-maybe)))
 
-(defun org-list-get-next-item (item struct prevs)
+(defun org-list-get-next-item (item _struct prevs)
   "Return next item in same sub-list as ITEM, or nil.
 STRUCT is the list structure.  PREVS is the alist of previous
 items, as returned by `org-list-prevs-alist'."
   (car (rassq item prevs)))
 
   "Return next item in same sub-list as ITEM, or nil.
 STRUCT is the list structure.  PREVS is the alist of previous
 items, as returned by `org-list-prevs-alist'."
   (car (rassq item prevs)))
 
-(defun org-list-get-prev-item (item struct prevs)
+(defun org-list-get-prev-item (item _struct prevs)
   "Return previous item in same sub-list as ITEM, or nil.
 STRUCT is the list structure.  PREVS is the alist of previous
 items, as returned by `org-list-prevs-alist'."
   "Return previous item in same sub-list as ITEM, or nil.
 STRUCT is the list structure.  PREVS is the alist of previous
 items, as returned by `org-list-prevs-alist'."
@@ -964,7 +964,7 @@ items, as returned by `org-list-prevs-alist'."
       (push next-item after-item))
     (append before-item (list item) (nreverse after-item))))
 
       (push next-item after-item))
     (append before-item (list item) (nreverse after-item))))
 
-(defun org-list-get-children (item struct parents)
+(defun org-list-get-children (item _struct parents)
   "List all children of ITEM, or nil.
 STRUCT is the list structure.  PARENTS is the alist of parents,
 as returned by `org-list-parents-alist'."
   "List all children of ITEM, or nil.
 STRUCT is the list structure.  PARENTS is the alist of parents,
 as returned by `org-list-parents-alist'."
@@ -982,7 +982,7 @@ STRUCT is the list structure."
 (defun org-list-get-bottom-point (struct)
   "Return point at bottom of list.
 STRUCT is the list structure."
 (defun org-list-get-bottom-point (struct)
   "Return point at bottom of list.
 STRUCT is the list structure."
-  (apply 'max
+  (apply #'max
         (mapcar (lambda (e) (org-list-get-item-end (car e) struct)) struct)))
 
 (defun org-list-get-list-begin (item struct prevs)
         (mapcar (lambda (e) (org-list-get-item-end (car e) struct)) struct)))
 
 (defun org-list-get-list-begin (item struct prevs)
@@ -1630,8 +1630,7 @@ as returned by `org-list-prevs-alist'."
           ;; Pretend that bullets are uppercase and check if alphabet
           ;; is sufficient, taking counters into account.
           (while item
           ;; Pretend that bullets are uppercase and check if alphabet
           ;; is sufficient, taking counters into account.
           (while item
-            (let ((bul (org-list-get-bullet item struct))
-                  (count (org-list-get-counter item struct)))
+            (let ((count (org-list-get-counter item struct)))
               ;; Virtually determine current bullet
               (if (and count (string-match "[a-zA-Z]" count))
                   ;; Counters are not case-sensitive.
               ;; Virtually determine current bullet
               (if (and count (string-match "[a-zA-Z]" count))
                   ;; Counters are not case-sensitive.
@@ -1728,7 +1727,7 @@ This function modifies STRUCT."
                  (replace-match "1" nil nil bullet))
                 ;; Not an ordered list: keep bullet.
                 (t bullet)))))))))
                  (replace-match "1" nil nil bullet))
                 ;; Not an ordered list: keep bullet.
                 (t bullet)))))))))
-    (mapc fix-bul (mapcar 'car struct))))
+    (mapc fix-bul (mapcar #'car struct))))
 
 (defun org-list-struct-fix-ind (struct parents &optional bullet-size)
   "Verify and correct indentation in STRUCT.
 
 (defun org-list-struct-fix-ind (struct parents &optional bullet-size)
   "Verify and correct indentation in STRUCT.
@@ -1756,7 +1755,7 @@ This function modifies STRUCT."
                                  org-list-indent-offset))
                 ;; If no parent, indent like top-point.
                (org-list-set-ind item struct top-ind))))))
                                  org-list-indent-offset))
                 ;; If no parent, indent like top-point.
                (org-list-set-ind item struct top-ind))))))
-    (mapc new-ind (mapcar 'car (cdr struct)))))
+    (mapc new-ind (mapcar #'car (cdr struct)))))
 
 (defun org-list-struct-fix-box (struct parents prevs &optional ordered)
   "Verify and correct checkboxes in STRUCT.
 
 (defun org-list-struct-fix-box (struct parents prevs &optional ordered)
   "Verify and correct checkboxes in STRUCT.
@@ -1771,7 +1770,7 @@ break this rule, the function will return the blocking item.  In
 all others cases, the return value will be nil.
 
 This function modifies STRUCT."
 all others cases, the return value will be nil.
 
 This function modifies STRUCT."
-  (let ((all-items (mapcar 'car struct))
+  (let ((all-items (mapcar #'car struct))
        (set-parent-box
         (function
          (lambda (item)
        (set-parent-box
         (function
          (lambda (item)
@@ -1942,8 +1941,8 @@ Initial position of cursor is restored after the changes."
       ;;    same amount of indentation.  Each slice follow the pattern
       ;;    (END BEG DELTA MAX-IND-OR-NIL).  Slices are returned in
       ;;    reverse order.
       ;;    same amount of indentation.  Each slice follow the pattern
       ;;    (END BEG DELTA MAX-IND-OR-NIL).  Slices are returned in
       ;;    reverse order.
-      (setq all-ends (sort (append (mapcar 'car itm-shift)
-                                  (org-uniquify (mapcar 'car end-list)))
+      (setq all-ends (sort (append (mapcar #'car itm-shift)
+                                  (org-uniquify (mapcar #'car end-list)))
                           '<))
       (while (cdr all-ends)
        (let* ((up (pop all-ends))
                           '<))
       (while (cdr all-ends)
        (let* ((up (pop all-ends))
@@ -2016,7 +2015,7 @@ previous item, plus ARGS extra arguments.
 
 FUNCTION is applied on items in reverse order.
 
 
 FUNCTION is applied on items in reverse order.
 
-As an example, \(org-apply-on-list \(lambda \(result\) \(1+ result\)\) 0\)
+As an example, \(org-apply-on-list \(lambda \(result) \(1+ result)) 0)
 will return the number of items in the current list.
 
 Sublists of the list are skipped.  Cursor is always at the
 will return the number of items in the current list.
 
 Sublists of the list are skipped.  Cursor is always at the
@@ -2237,7 +2236,7 @@ item is invisible."
          t)))))
 
 (defun org-list-repair ()
          t)))))
 
 (defun org-list-repair ()
-  "Fix indentation, bullets and checkboxes is the list at point."
+  "Fix indentation, bullets and checkboxes in the list at point."
   (interactive)
   (unless (org-at-item-p) (error "This is not a list"))
   (let* ((struct (org-list-struct))
   (interactive)
   (unless (org-at-item-p) (error "This is not a list"))
   (let* ((struct (org-list-struct))
@@ -2327,7 +2326,7 @@ in subtree, ignoring drawers."
           lim-up
           lim-down
           (drawer-re (concat "^[ \t]*:\\("
           lim-up
           lim-down
           (drawer-re (concat "^[ \t]*:\\("
-                             (mapconcat 'regexp-quote org-drawers "\\|")
+                             (mapconcat #'regexp-quote org-drawers "\\|")
                              "\\):[ \t]*$"))
           (keyword-re (concat "^[ \t]*\\<\\(" org-scheduled-string
                               "\\|" org-deadline-string
                              "\\):[ \t]*$"))
           (keyword-re (concat "^[ \t]*\\<\\(" org-scheduled-string
                               "\\|" org-deadline-string
@@ -2335,7 +2334,7 @@ in subtree, ignoring drawers."
                               "\\|" org-clock-string "\\)"
                               " *[[<]\\([^]>]+\\)[]>]"))
           (orderedp (org-entry-get nil "ORDERED"))
                               "\\|" org-clock-string "\\)"
                               " *[[<]\\([^]>]+\\)[]>]"))
           (orderedp (org-entry-get nil "ORDERED"))
-          (bounds
+          (_bounds
            ;; In a region, start at first item in region.
            (cond
             ((org-region-active-p)
            ;; In a region, start at first item in region.
            (cond
             ((org-region-active-p)
@@ -2391,7 +2390,7 @@ in subtree, ignoring drawers."
               (bottom (copy-marker (org-list-get-bottom-point struct)))
               (items-to-toggle (org-remove-if
                                 (lambda (e) (or (< e lim-up) (> e lim-down)))
               (bottom (copy-marker (org-list-get-bottom-point struct)))
               (items-to-toggle (org-remove-if
                                 (lambda (e) (or (< e lim-up) (> e lim-down)))
-                                (mapcar 'car struct))))
+                                (mapcar #'car struct))))
          (mapc (lambda (e) (org-list-set-checkbox
                             e struct
                             ;; If there is no box at item, leave as-is
          (mapc (lambda (e) (org-list-set-checkbox
                             e struct
                             ;; If there is no box at item, leave as-is
@@ -2473,7 +2472,7 @@ With optional prefix argument ALL, do this for the whole buffer."
                          (items
                           (cond
                            ((and recursivep item) (org-list-get-subtree item s))
                          (items
                           (cond
                            ((and recursivep item) (org-list-get-subtree item s))
-                           (recursivep (mapcar 'car s))
+                           (recursivep (mapcar #'car s))
                            (item (org-list-get-children item s par))
                            (t (org-list-get-all-items
                                (org-list-get-top-point s) s pre))))
                            (item (org-list-get-children item s par))
                            (t (org-list-get-all-items
                                (org-list-get-top-point s) s pre))))
@@ -2486,7 +2485,7 @@ With optional prefix argument ALL, do this for the whole buffer."
                 structs)
                (cons c-on c-all)))))
          (backup-end 1)
                 structs)
                (cons c-on c-all)))))
          (backup-end 1)
-         cookies-list structs-bak box-num)
+         cookies-list structs-bak)
       (goto-char (car bounds))
       ;; 1. Build an alist for each cookie found within BOUNDS.  The
       ;;    key will be position at beginning of cookie and values
       (goto-char (car bounds))
       ;; 1. Build an alist for each cookie found within BOUNDS.  The
       ;;    key will be position at beginning of cookie and values
@@ -2556,8 +2555,8 @@ With optional prefix argument ALL, do this for the whole buffer."
                     (checked (car (nth 3 cookie)))
                     (total (cdr (nth 3 cookie)))
                     (new (if percentp
                     (checked (car (nth 3 cookie)))
                     (total (cdr (nth 3 cookie)))
                     (new (if percentp
-                             (format "[%d%%]" (/ (* 100 checked)
-                                                 (max 1 total)))
+                             (format "[%d%%]" (floor (* 100.0 checked)
+                                                     (max 1 total)))
                            (format "[%d/%d]" checked total))))
                (goto-char beg)
                (insert new)
                            (format "[%d/%d]" checked total))))
                (goto-char beg)
                (insert new)
@@ -2749,6 +2748,7 @@ If a region is active, all items inside will be moved."
      (t (error "Not at an item")))))
 
 (defvar org-tab-ind-state)
      (t (error "Not at an item")))))
 
 (defvar org-tab-ind-state)
+(defvar org-adapt-indentation)
 (defun org-cycle-item-indentation ()
   "Cycle levels of indentation of an empty item.
 The first run indents the item, if applicable.  Subsequent runs
 (defun org-cycle-item-indentation ()
   "Cycle levels of indentation of an empty item.
 The first run indents the item, if applicable.  Subsequent runs
@@ -2884,7 +2884,7 @@ ignores hidden links."
                          (save-excursion (re-search-forward org-ts-regexp-both
                                                             (point-at-eol) t)))
                      (org-time-string-to-seconds (match-string 0)))
                          (save-excursion (re-search-forward org-ts-regexp-both
                                                             (point-at-eol) t)))
                      (org-time-string-to-seconds (match-string 0)))
-                    (t (org-float-time now))))
+                    (t (float-time now))))
                   ((= dcst ?x) (or (and (stringp (match-string 1))
                                         (match-string 1))
                                    ""))
                   ((= dcst ?x) (or (and (stringp (match-string 1))
                                         (match-string 1))
                                    ""))
@@ -2931,22 +2931,22 @@ For example, the following list:
 
 will be parsed as:
 
 
 will be parsed as:
 
-\(ordered
-  \(nil \"first item\"
-  \(unordered
-    \(nil \"sub-item one\"\)
-    \(nil \"[CBON] sub-item two\"\)\)
-  \"more text in first item\"\)
-  \(3 \"last item\"\)\)
+ (ordered
+  (nil \"first item\"
+  (unordered
+    (nil \"sub-item one\")
+    (nil \"[CBON] sub-item two\"))
+  \"more text in first item\")
+  (3 \"last item\"))
 
 Point is left at list end."
 
 Point is left at list end."
+  (defvar parse-item)                   ;FIXME: Or use `cl-labels' or `letrec'.
   (let* ((struct (org-list-struct))
         (prevs (org-list-prevs-alist struct))
         (parents (org-list-parents-alist struct))
         (top (org-list-get-top-point struct))
         (bottom (org-list-get-bottom-point struct))
         out
   (let* ((struct (org-list-struct))
         (prevs (org-list-prevs-alist struct))
         (parents (org-list-parents-alist struct))
         (top (org-list-get-top-point struct))
         (bottom (org-list-get-bottom-point struct))
         out
-        parse-item                     ; for byte-compiler
         (get-text
          (function
           ;; Return text between BEG and END, trimmed, with
         (get-text
          (function
           ;; Return text between BEG and END, trimmed, with
@@ -3072,7 +3072,7 @@ for this list."
              (re-search-forward (org-item-beginning-re) bottom-point t)
              (match-beginning 0)))
           (plain-list (buffer-substring-no-properties top-point bottom-point))
              (re-search-forward (org-item-beginning-re) bottom-point t)
              (match-beginning 0)))
           (plain-list (buffer-substring-no-properties top-point bottom-point))
-          beg txt)
+          beg)
       (unless (fboundp transform)
        (error "No such transformation function %s" transform))
       (let ((txt (funcall transform plain-list)))
       (unless (fboundp transform)
        (error "No such transformation function %s" transform))
       (let ((txt (funcall transform plain-list)))
@@ -3082,7 +3082,8 @@ for this list."
          (unless (re-search-forward
                   (concat "BEGIN RECEIVE ORGLST +"
                           name
          (unless (re-search-forward
                   (concat "BEGIN RECEIVE ORGLST +"
                           name
-                          "\\([ \t]\\|$\\)") nil t)
+                          "\\([ \t]\\|$\\)")
+                   nil t)
            (error "Don't know where to insert translated list"))
          (goto-char (match-beginning 0))
          (beginning-of-line 2)
            (error "Don't know where to insert translated list"))
          (goto-char (match-beginning 0))
          (beginning-of-line 2)
@@ -3230,7 +3231,7 @@ items."
                                      items (or (eval isep) ""))))))))
     (concat (funcall export-sublist list 0) "\n")))
 
                                      items (or (eval isep) ""))))))))
     (concat (funcall export-sublist list 0) "\n")))
 
-(defun org-list-to-latex (list &optional params)
+(defun org-list-to-latex (list &optional _params)
   "Convert LIST into a LaTeX list.
 LIST is as string representing the list to transform, as Org
 syntax.  Return converted list as a string."
   "Convert LIST into a LaTeX list.
 LIST is as string representing the list to transform, as Org
 syntax.  Return converted list as a string."
@@ -3244,7 +3245,7 @@ syntax.  Return converted list as a string."
   (require 'ox-html)
   (org-export-string-as list 'html t))
 
   (require 'ox-html)
   (org-export-string-as list 'html t))
 
-(defun org-list-to-texinfo (list &optional params)
+(defun org-list-to-texinfo (list &optional _params)
   "Convert LIST into a Texinfo list.
 LIST is as string representing the list to transform, as Org
 syntax.  Return converted list as a string."
   "Convert LIST into a Texinfo list.
 LIST is as string representing the list to transform, as Org
 syntax.  Return converted list as a string."
@@ -3255,14 +3256,15 @@ syntax.  Return converted list as a string."
   "Convert LIST into an Org subtree.
 LIST is as returned by `org-list-parse-list'.  PARAMS is a property list
 with overruling parameters for `org-list-to-generic'."
   "Convert LIST into an Org subtree.
 LIST is as returned by `org-list-parse-list'.  PARAMS is a property list
 with overruling parameters for `org-list-to-generic'."
+  (defvar get-stars) (defvar org--blankp)
   (let* ((rule (cdr (assq 'heading org-blank-before-new-entry)))
         (level (org-reduced-level (or (org-current-level) 0)))
   (let* ((rule (cdr (assq 'heading org-blank-before-new-entry)))
         (level (org-reduced-level (or (org-current-level) 0)))
-        (blankp (or (eq rule t)
+        (org--blankp (or (eq rule t)
                     (and (eq rule 'auto)
                          (save-excursion
                            (outline-previous-heading)
                            (org-previous-line-empty-p)))))
                     (and (eq rule 'auto)
                          (save-excursion
                            (outline-previous-heading)
                            (org-previous-line-empty-p)))))
-        (get-stars
+        (get-stars ;FIXME: Can't rename without renaming it in org.el as well!
          (function
           ;; Return the string for the heading, depending on depth D
           ;; of current sub-list.
          (function
           ;; Return the string for the heading, depending on depth D
           ;; of current sub-list.
@@ -3277,12 +3279,12 @@ with overruling parameters for `org-list-to-generic'."
      list
      (org-combine-plists
       '(:splice t
      list
      (org-combine-plists
       '(:splice t
-               :dtstart " " :dtend " "
-               :istart (funcall get-stars depth)
-               :icount (funcall get-stars depth)
-               :isep (if blankp "\n\n" "\n")
-               :csep (if blankp "\n\n" "\n")
-               :cbon "DONE" :cboff "TODO" :cbtrans "TODO")
+        :dtstart " " :dtend " "
+        :istart (funcall get-stars depth)
+        :icount (funcall get-stars depth)
+        :isep (if org--blankp "\n\n" "\n")
+        :csep (if org--blankp "\n\n" "\n")
+        :cbon "DONE" :cboff "TODO" :cbtrans "TODO")
       params))))
 
 (provide 'org-list)
       params))))
 
 (provide 'org-list)