emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Flexible plain list bullets
@ 2012-04-19  1:24 Mark E. Shoulson
  2012-04-19  8:18 ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Mark E. Shoulson @ 2012-04-19  1:24 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/html, Size: 1429 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Lists-enable-customization-for-arbitrary-characters-.patch --]
[-- Type: text/x-patch; name="0001-Lists-enable-customization-for-arbitrary-characters-.patch", Size: 5200 bytes --]

From 5db3081b9487c09b17c7accfcf1b25f45002aa13 Mon Sep 17 00:00:00 2001
From: Mark Shoulson <mark@kli.org>
Date: Wed, 18 Apr 2012 20:55:41 -0400
Subject: [PATCH] Lists: enable customization for arbitrary characters for
 plain list bullets

* lisp/org-list.el (org-list-bulletcharlist): new custom variable
to set a list of characters for use as the bullets in plain lists.
Entails a few other variables set along with it.
---
 lisp/org-list.el |   67 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 882ce3d..c751d1f 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -360,17 +360,60 @@ specifically, type `block' is determined by the variable
   "Regex corresponding to the end of a list.
 It depends on `org-empty-line-terminates-plain-lists'.")
 
-(defconst org-list-full-item-re
-  (concat "^[ \t]*\\(\\(?:[-+*]\\|\\(?:[0-9]+\\|[A-Za-z]\\)[.)]\\)\\(?:[ \t]+\\|$\\)\\)"
-	  "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
-	  "\\(?:\\(\\[[ X-]\\]\\)\\(?:[ \t]+\\|$\\)\\)?"
-	  "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?")
+;; There shouldn't really have to be two different values here, since
+;; they need to be changed in sync...
+
+(defvar org-list-bullet-re)
+(defvar org-list-bullet-chars)
+(defvar org-list-full-item-re nil
   "Matches a list item and puts everything into groups:
 group 1: bullet
 group 2: counter
 group 3: checkbox
 group 4: description tag")
 
+(defcustom org-list-bulletcharlist '(?+ ?- ?*)
+  "Characters used as unordered plain list bullets.
+If nil, defaults to (?- ?+ ?*), i.e. hyphen, plus, and *.  If * is present,
+it only matches when not at the beginning of the line (it must be preceded
+by whitespace).
+
+Using letters as bullet characters is not recommended, as they also get
+interpreted as ordered lists."
+  :group 'org-plain-lists
+  :type '(choice (const nil)
+		 (const :tag "(+ - *)" '(?+ ?- ?*))
+		 (const :tag "(+ - * ‣)" '(?+ ?- ?* ?‣))
+		 (const :tag "(☞ ❦ ❧ ❥)" '(?☞ ?❦ ?❧ ?❥))
+		 (repeat character))
+  :set (lambda (name val)
+  	 (let* ((val (or val '(?- ?+ ?*)))
+  		;; - mustn't be in the middle!  Place it in front.
+  		(val (if (member ?- val)
+			 (cons ?- (remove ?- val))
+		       val))
+  		(star-p (member ?* val))
+  		(val (remove ?* val)))
+	   (setq org-list-bullet-chars 
+		 (concat (eval `(string ,@val))
+			 (when star-p "*")))
+	   (setq org-list-full-item-re
+		 (concat "^[ \t]*\\(\\(?:[" org-list-bullet-chars "]"
+			 "\\|\\(?:[0-9]+\\|[A-Za-z]\\)[.)]\\)\\(?:[ \t]+\\|$\\)\\)"
+			 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
+			 "\\(?:\\(\\[[ X-]\\]\\)\\(?:[ \t]+\\|$\\)\\)?"
+			 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"))
+  	   ;; * is a special case
+  	   (setq org-list-bullet-re 
+  		 (concat 
+  		  "\\(?:"
+  		  (when star-p "[[:blank:]]+\\*")
+  		  (when (and star-p val) "\\|")
+  		  "[[:blank:]]*["
+  		  (when val (eval `(string ,@val)))
+  		  "]\\)")))
+  	 (set name val)))
+
 (defun org-item-re ()
   "Return the correct regular expression for plain lists."
   (let ((term (cond
@@ -379,8 +422,8 @@ group 4: description tag")
 	       ((= org-plain-list-ordered-item-terminator ?.) "\\.")
 	       (t "[.)]")))
 	(alpha (if org-alphabetical-lists "\\|[A-Za-z]" "")))
-    (concat "\\([ \t]*\\([-+]\\|\\(\\([0-9]+" alpha "\\)" term
-	    "\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")))
+    (concat "\\(" org-list-bullet-re "\\|[ \t]*\\(\\(\\([0-9]+" alpha "\\)" term
+	    "\\)\\)\\)\\([ \t]+\\|$\\)")))
 
 (defsubst org-item-beginning-re ()
   "Regexp matching the beginning of a plain list item."
@@ -2229,7 +2272,7 @@ is an integer, 0 means `-', 1 means `+' etc.  If WHICH is
 		     (t (org-trim bullet))))
            ;; Compute list of possible bullets, depending on context.
 	   (bullet-list
-	    (append '("-" "+" )
+	    (append (mapcar 'char-to-string (string-to-list org-list-bullet-chars))
 		    ;; *-bullets are not allowed at column 0.
 		    (unless (and bullet-rule-p
 				 (looking-at "\\S-")) '("*"))
@@ -2403,7 +2446,9 @@ With optional prefix argument ALL, do this for the whole buffer."
   (interactive "P")
   (save-excursion
     (let ((cookie-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
-	  (box-re "^[ \t]*\\([-+*]\\|\\([0-9]+\\|[A-Za-z]\\)[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?\\(\\[[- X]\\]\\)")
+	  (box-re (concat 
+		   "^[ \t]*\\([" org-list-bullet-chars "]"
+		   "\\|\\([0-9]+\\|[A-Za-z]\\)[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?\\(\\[[- X]\\]\\)"))
 	  (recursivep
 	   (or (not org-hierarchical-checkbox-statistics)
 	       (string-match "\\<recursive\\>"
@@ -2812,7 +2857,9 @@ COMPARE-FUNC to compare entries."
 				       (point) struct))))
 	     (value-to-sort
 	      (lambda ()
-		(when (looking-at "[ \t]*[-+*0-9.)]+\\([ \t]+\\[[- X]\\]\\)?[ \t]+")
+		(when (looking-at (concat
+				   "[ \t]*\\(?:[" org-list-bullet-chars "]"
+				   "\\|[0-9.)]\\)+\\([ \t]+\\[[- X]\\]\\)?[ \t]+"))
 		  (cond
 		   ((= dcst ?n)
 		    (string-to-number (buffer-substring (match-end 0)
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-04-22 13:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-19  1:24 Flexible plain list bullets Mark E. Shoulson
2012-04-19  8:18 ` Nicolas Goaziou
2012-04-19  9:40   ` suvayu ali
2012-04-19 10:01     ` Carsten Dominik
2012-04-20  4:19       ` Mark E. Shoulson
2012-04-20  5:58         ` Jambunathan K
2012-04-20 13:38         ` Bastien
2012-04-20 22:18           ` Mark E. Shoulson
2012-04-20 22:35             ` Bastien
2012-04-22 13:43               ` Mike McLean
2012-04-20 14:51         ` Carsten Dominik

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).