unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#6531: patch for rst.el updated (patch format revised)
@ 2010-06-28 13:58 Wei-Wei Guo
  2012-04-12 17:41 ` Lars Magne Ingebrigtsen
  2012-04-12 20:30 ` Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: Wei-Wei Guo @ 2010-06-28 13:58 UTC (permalink / raw)
  To: 6531

[-- Attachment #1: Type: text/plain, Size: 698 bytes --]

Dear all,

I just notice the CONTRIBUTE file and find the format of my patch is not right, so I correct
it and send the mail again. Sorry for that.

I updated my patch for rst.el of Emacs 23. Here are the previous changes:

    http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=1610

The update including:

- Insert bullet list by 'M-Enter'.
- Insert number list "#." by 'M-Enter' with any prefix.
- Insert number list of a specific number of various styles by 'M-Enter" with a number prefix.
- Insert directive by 'C-c C-d'.
- Insert directive option by 'C-c C-o'.
- Remove the dependency on a2r.el. Now all the patched codes are from mine.

Hope it's helpful.


Best wishes,
Wei-Wei




[-- Attachment #2: rst.patch --]
[-- Type: text/plain, Size: 45646 bytes --]

*** rst.el.old	2010-05-10 15:49:49.000000000 +0800
--- rst.el	2010-06-28 16:22:05.000000000 +0800
***************
*** 36,41 ****
--- 36,43 ----
  ;;   from it;
  ;; - Functions to insert and automatically update a TOC in your source
  ;;   document;
+ ;; - Function to insert list, processing item bullets and enumerations 
+ ;;   automatically;
  ;; - Font-lock highlighting of notable reStructuredText structures;
  ;; - Some other convenience functions.
  ;;
***************
*** 166,176 ****
  ;; - numbering: automatically detect if we have a section-numbering directive in
  ;;   the corresponding section, to render the toc.
  ;;
- ;; bulleted and enumerated list items
- ;; ----------------------------------
- ;; - We need to provide way to rebullet bulleted lists, and that would include
- ;;   automatic enumeration as well.
- ;;
  ;; Other
  ;; -----
  ;; - It would be nice to differentiate between text files using
--- 168,173 ----
***************
*** 239,252 ****
      ;; Section Decorations.
      ;;
      ;; The adjustment function that decorates or rotates a section title.
!     (define-key map [(control c) (control a)] 'rst-adjust)
!     (define-key map [(control c) (control ?=)] 'rst-adjust)
      (define-key map [(control ?=)] 'rst-adjust) ;; (Does not work on the Mac OSX.)
      ;; Display the hierarchy of decorations implied by the current document contents.
!     (define-key map [(control c) (control h)] 'rst-display-decorations-hierarchy)
      ;; Homogeneize the decorations in the document.
      (define-key map [(control c) (control s)] 'rst-straighten-decorations)
! ;;    (define-key map [(control c) (control s)] 'rst-straighten-deco-spacing)
  
      ;;
      ;; Section Movement and Selection.
--- 236,249 ----
      ;; Section Decorations.
      ;;
      ;; The adjustment function that decorates or rotates a section title.
!     ;(define-key map [(control c) (control a)] 'rst-adjust)
!     ;(define-key map [(control c) (control ?=)] 'rst-adjust)
      (define-key map [(control ?=)] 'rst-adjust) ;; (Does not work on the Mac OSX.)
      ;; Display the hierarchy of decorations implied by the current document contents.
!     (define-key map [(control c) (control t)] 'rst-display-decorations-hierarchy)
      ;; Homogeneize the decorations in the document.
      (define-key map [(control c) (control s)] 'rst-straighten-decorations)
!     ;(define-key map [(control c) (control s)] 'rst-straighten-deco-spacing)
  
      ;;
      ;; Section Movement and Selection.
***************
*** 254,292 ****
      ;; Mark the subsection where the cursor is.
      (define-key map [(control c) (control m)] 'rst-mark-section)
      ;; Move forward/backward between section titles.
!     (define-key map [(control c) (control n)] 'rst-forward-section)
!     (define-key map [(control c) (control p)] 'rst-backward-section)
  
      ;;
      ;; Operating on Blocks of Text.
      ;;
      ;; Makes paragraphs in region as a bullet list.
!     (define-key map [(control c) (control b)] 'rst-bullet-list-region)
      ;; Makes paragraphs in region as a enumeration.
!     (define-key map [(control c) (control e)] 'rst-enumerate-region)
      ;; Converts bullets to an enumeration.
!     (define-key map [(control c) (control v)] 'rst-convert-bullets-to-enumeration)
      ;; Makes region a line-block.
!     (define-key map [(control c) (control d)] 'rst-line-block-region)
      ;; Make sure that all the bullets in the region are consistent.
!     (define-key map [(control c) (control w)] 'rst-straighten-bullets-region)
      ;; Shift region left or right (taking into account of enumerations/bullets, etc.).
      (define-key map [(control c) (control l)] 'rst-shift-region-left)
      (define-key map [(control c) (control r)] 'rst-shift-region-right)
      ;; Comment/uncomment the active region.
!     (define-key map [(control c) (control c)] 'comment-region)
  
      ;;
      ;; Table-of-Contents Features.
      ;;
      ;; Enter a TOC buffer to view and move to a specific section.
      (define-key map [(control c) (control t)] 'rst-toc)
!     ;; Insert a TOC here.
!     (define-key map [(control c) (control i)] 'rst-toc-insert)
      ;; Update the document's TOC (without changing the cursor position).
      (define-key map [(control c) (control u)] 'rst-toc-update)
      ;; Got to the section under the cursor (cursor must be in TOC).
!     (define-key map [(control c) (control f)] 'rst-goto-section)
  
      ;;
      ;; Converting Documents from Emacs.
--- 251,325 ----
      ;; Mark the subsection where the cursor is.
      (define-key map [(control c) (control m)] 'rst-mark-section)
      ;; Move forward/backward between section titles.
!     (define-key map [(meta n)] 'rst-forward-section)
!     (define-key map [(meta p)] 'rst-backward-section)
  
      ;;
      ;; Operating on Blocks of Text.
      ;;
+     ;; Inserts bullet list or enumeration list.
+     (define-key map [(meta return)] 'rst-insert-list)
+     ;; Inserts definition list.
+     ;(define-key map [(control c) t] 'rst-insert-definition)
+     ;; Inserts field list.
+     ;(define-key map [(control c) f] 'rst-insert-field)
      ;; Makes paragraphs in region as a bullet list.
!     ;(define-key map [(control c) (control b)] 'rst-bullet-list-region)
      ;; Makes paragraphs in region as a enumeration.
!     ;(define-key map [(control c) (control e)] 'rst-enumerate-region)
      ;; Converts bullets to an enumeration.
!     ;(define-key map [(control c) (control v)] 'rst-convert-bullets-to-enumeration)
      ;; Makes region a line-block.
!     ;(define-key map [(control c) (control d)] 'rst-line-block-region)
      ;; Make sure that all the bullets in the region are consistent.
!     ;(define-key map [(control c) (control w)] 'rst-straighten-bullets-region)
      ;; Shift region left or right (taking into account of enumerations/bullets, etc.).
      (define-key map [(control c) (control l)] 'rst-shift-region-left)
      (define-key map [(control c) (control r)] 'rst-shift-region-right)
      ;; Comment/uncomment the active region.
!     ;(define-key map [(control c) (control c)] 'comment-region)
! 
!     ;; Insert option or directive.
!     (define-key map [(control c) (control o)] 'rst-insert-option)
!     (define-key map [(control c) (control d)] 'rst-insert-directive)
!     ;; Insert text replace definition.
!     ;(define-key map [(control c) t] 'rst-insert-replace)
!     ;; Insert image and figures
!     ;(define-key map [(control c) p] 'rst-insert-image)
!     ;(define-key map [(control c) m] 'rst-insert-figure)
!     ;; Insert admonition
!     ;(define-key map [(control c) t] 'rst-insert-admonition)
! 
!     ;; 
!     ;; Hypylink, Footnote, and Citation Features.
!     ;; 
!     (define-key map [(control c) (control h)] 'rst-insert-link)
!     ;; Insert hyperlink
!     ;(define-key map [(control c) l] 'rst-insert-inline-link)
!     ;; Insert footnote
!     ;(define-key map [(control c) f] 'rst-insert-footnote)
!     ;; Insert citation
!     ;(define-key map [(control c) c] 'rst-insert-citation)
!     ;; Hyperlink jumping
!     (define-key map [(control c) (l)] 'rst-link-jump-to-reference)
!     (define-key map [(control c) (n)] 'rst-link-jump-within-targets)
!     (define-key map [(control c) (t)] 'rst-link-jump-to-target)
!     ;; Footnote and citation jumping
!     (define-key map [(control c) (r)] 'rst-footnote-citation-jump-to-reference)
!     (define-key map [(control c) (m)] 'rst-footnote-citation-jump-within-targets)
!     (define-key map [(control c) (u)] 'rst-footnote-citation-jump-to-target)
  
      ;;
      ;; Table-of-Contents Features.
      ;;
      ;; Enter a TOC buffer to view and move to a specific section.
      (define-key map [(control c) (control t)] 'rst-toc)
!     ;; Insert a TOC here. use `rst-insert-directive' instead
!     ;(define-key map [(control c) i] 'rst-toc-insert)
      ;; Update the document's TOC (without changing the cursor position).
      (define-key map [(control c) (control u)] 'rst-toc-update)
      ;; Got to the section under the cursor (cursor must be in TOC).
!     ;(define-key map [(control c) (control f)] 'rst-goto-section)
  
      ;;
      ;; Converting Documents from Emacs.
*************** This inherits from Text mode.")
*** 344,351 ****
  
  
  (defcustom rst-mode-hook nil
!   "Hook run when Rst mode is turned on.
! The hook for Text mode is run before this one."
    :group 'rst
    :type '(hook))
  
--- 377,384 ----
  
  
  (defcustom rst-mode-hook nil
!   "Hook run when Rst Mode is turned on.
! The hook for Text Mode is run before this one."
    :group 'rst
    :type '(hook))
  
*************** in order to adapt it to our preferred st
*** 1464,1471 ****
  				(lambda (deco)
  				  (cons (rst-position (cdr deco) hier)
  					(let ((m (make-marker)))
! 					  (goto-char (point-min))
! 					  (forward-line (1- (car deco)))
  					  (set-marker m (point))
  					  m)))
  				alldecos))
--- 1497,1504 ----
  				(lambda (deco)
  				  (cons (rst-position (cdr deco) hier)
  					(let ((m (make-marker)))
!  					  (goto-char (point-min))
!  					  (forward-line (1- (car deco)))
  					  (set-marker m (point))
  					  m)))
  				alldecos))
*************** section levels."
*** 1499,1512 ****
        ;; adjust for the changes in the document.
        (dolist (deco (nreverse alldecos))
  	;; Go to the appropriate position.
! 	(goto-char (point-min))
! 	(forward-line (1- (car deco)))
  	(insert "@\n")
  ;; FIXME: todo, we
  	)
      )))
  
  
  (defun rst-find-pfx-in-region (beg end pfx-re)
    "Find all the positions of prefixes in region between BEG and END.
  This is used to find bullets and enumerated list items.  PFX-RE
--- 1532,1773 ----
        ;; adjust for the changes in the document.
        (dolist (deco (nreverse alldecos))
  	;; Go to the appropriate position.
!  	(goto-char (point-min))
!  	(forward-line (1- (car deco)))
  	(insert "@\n")
  ;; FIXME: todo, we
  	)
      )))
  
  
+ ;=================================================
+ ; list related functions.
+ 
+ (defconst roman-number-list
+   '("I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX" "X" "XI" "XII" "XIII" "XIV" "XV"
+     "XVI" "XVII" "XVIII" "XIX" "XX" "XXI" "XXII" "XXIII" "XXIV" "XXV" "XXVI" "XXVII"
+     "XXVIII" "XXIX" "XXX" "XXXI" "XXXII" "XXXIII" "XXXIV" "XXXV" "XXXVI" "XXXVII"
+     "XXXVIII" "XXXIX" "XL" "XLI" "XLII" "XLIII" "XLIV" "XLV" "XLVI" "XLVII" "XLVIII"
+     "XLIX" "L")
+   "List of Roman numerals.")
+ 
+ (defconst letter-list
+   '("A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M"
+     "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z")
+   "List of Latin letter.")
+ 
+ (defvar rst-re-bullets
+   (format "\\([%s][ \t]\\)[^ \t]" (regexp-quote (concat rst-bullets)))
+   "Regexp for finding bullets.")
+ 
+ (defvar rst-initial-enums
+   '("#." "1." "a." "A." "I." "i." "(1)" "(a)" "(A)" "(I)" "(i)" "1)" "a)" "A)" "I)" "i)")
+   "List of initial enumerates.")
+ 
+ (defvar rst-initial-items
+   (append (mapcar 'char-to-string rst-bullets) rst-initial-enums)
+   "List of initial items. It's collection of bullets and enumerations")
+ 
+ (defvar rst-re-enumerates
+   (format "^[ \t]*\\(%s\\|%s\\)[ \t]"
+           "\\([0-9]+\\|[a-zA-Z]\\|[IVXLCDMivxlcdm]+\\)\\."
+           "(?\\([0-9]+\\|[a-zA-Z]\\|[IVXLCDMivxlcdm]+\\))")
+   "Regexp for finding enumerates (# is not included).")
+ 
+ (defvar rst-re-items
+   (format "^[ \t]*\\(%s\\|%s\\|%s\\)[ \t]"
+           (format "[%s]" (regexp-quote (concat rst-bullets)))
+           "\\(#\\|[a-z]\\|[0-9]+\\|[A-Z]\\|[IVXLCDM]+\\|[ivxlcdm]+\\)\\."
+           "(?\\([a-z]\\|[0-9]+\\|[A-Z]\\|[IVXLCDM]+\\|[ivxlcdm]+\\))")
+   "Regexp for finding bullets and enumerates.")
+ 
+ (defun rst-insert-list-pos (newitem)
+   "Arrage relative position of a newly inserted list item.
+ 
+ Adding a new list might consider three situations:
+ 
+  (a) Current line is a blank line.
+  (b) Previous line is a blank line.
+  (c) Following line is a blank line.
+ 
+ When (a) and (b), just add the new list at current line. 
+ 
+ when (a) and not (b), add a blank line before adding the new list.
+ 
+ When not (a), add a blank line and a new line at current point. 
+ 
+ Other situations are just ignored and left to users themselves."
+   (if (save-excursion
+         (beginning-of-line)
+         (looking-at "^[ \t]*$"))
+       (if (save-excursion
+             (forward-line -1)
+             (looking-at "^[ \t]*$"))
+           (insert (concat newitem " "))
+         (insert (concat "\n" newitem " ")))
+     (progn 
+       (insert (concat "\n\n" newitem " ")))))
+ 
+ (defun rst-insert-list-new-bullet ()
+   "Insert a new list bullet.
+ "
+   (interactive)
+   (let (itemstyle)
+     (setq itemstyle "-")
+     (rst-insert-list-pos itemstyle)))
+ 
+ (defun rst-insert-list-new-item (itemno)
+   "Insert a new list item.
+ 
+ User is asked to select the item style first, for example (a), i), +. Use TAB 
+ for completition and choices.
+ 
+ If user selects bullets or #, it's just added with position arranged by 
+ `rst-insert-list-new-pos'. 
+ 
+ If user selects enumerates, a further prompt is given. User need to input a 
+ starting item, for example 'e' for 'A)' style. The position is also arranged by
+ `rst-insert-list-new-pos'.
+ "
+   (interactive "P")
+   (if (not itemno)
+       (setq itemno 1))
+   (setq itemno (1- itemno))
+   (let (itemstyle itemfirst)
+     (setq itemstyle (completing-read "Providing perfered item (default '#.'): "
+                                      rst-initial-items nil t nil nil "#."))
+     (when (string-match "[aA1Ii]" itemstyle)
+       (setq itemfirst (match-string 0 itemstyle))
+       (cond ((equal itemfirst "A") 
+              (setq itemstyle (replace-match (nth itemno letter-list) 
+                                             nil nil itemstyle)))
+             ((equal itemfirst "a") 
+              (setq itemstyle (replace-match (downcase (nth itemno letter-list)) 
+                                             nil nil itemstyle)))
+             ((equal itemfirst "I") 
+              (setq itemstyle (replace-match (nth itemno roman-number-list) 
+                                             nil nil itemstyle)))
+             ((equal itemfirst "i") 
+              (setq itemstyle (replace-match (downcase (nth itemno roman-number-list)) 
+                                             nil nil itemstyle)))
+             ((equal itemfirst "1") 
+              (setq itemstyle (replace-match (number-to-string (1+ itemno)) 
+                                             nil nil itemstyle)))
+             ))
+     (rst-insert-list-pos itemstyle)))
+ 
+ (defun rst-list-match-string (reg)
+   "Match a regex in a line and return the matched string by match-string.
+ 
+ If nothing matched, a empty string is returned."
+   (let (matched)
+     (save-excursion
+       (end-of-line)
+       (if (re-search-backward reg (line-beginning-position) t)
+           (setq matched (match-string 0))
+         (setq matched "")))
+     matched))
+ 
+ (defun rst-insert-list-continue ()
+   "Insert a list item with current list style and indentation level.
+ 
+ The function works for all style of bullet lists and enumeration lists. Only one 
+ thing need to be noticed: 
+ 
+ List style alphabetical list, such as 'a.', and roman numerical list, such as 'i.', 
+ have some overlapping items, for example 'v.' The function can deal with the 
+ problem elegantly in most situations. But when those overlapped list proceeded 
+ by a blank line, it is hard to determine which type to use automatically. The 
+ function uses roman numerical list defaultly. If you want alphabetical list, just 
+ use a prefix (\\[universal-argument]).
+ "
+   (interactive)
+   (let (curitem newitem itemno previtem tmpitem)
+     (setq curitem (rst-list-match-string rst-re-items))
+     (cond ((string-match (format "#.\\|[%s]" 
+                                  (regexp-quote (concat rst-bullets))) curitem)
+            (setq newitem curitem))
+           ((string-match "[0-9]+" curitem)
+            (progn
+              (setq itemno (1+
+                            (string-to-number
+                             (match-string 0 curitem))))
+              (setq newitem (replace-match
+                             (number-to-string itemno)
+                             nil nil curitem))))
+           ((and (string-match "[IVXLCDMivxlcdm]+" curitem)
+                 (progn 
+                   (setq tmpitem (match-string 0 curitem))
+                   (or (> (length tmpitem) 1) 
+                       (and (= (length tmpitem) 1) 
+                            (progn
+                              (save-excursion
+                                (forward-line -1)
+                                (setq previtem (rst-list-match-string rst-re-enumerates))
+                                (when (string-match "[a-zA-Z]+" previtem)
+                                  (setq previtem (match-string 0 previtem))))
+                              (or (> (length previtem) 1)
+                                  (= (length previtem) 0)))))))
+            (progn
+              (string-match "[IVXLCDMivxlcdm]+" curitem)
+              (if (isearch-no-upper-case-p tmpitem nil)
+                  (progn
+                    (setq itemno (car (cdr (member 
+                                            (match-string 0 (upcase curitem)) 
+                                            roman-number-list))))
+                    (setq newitem (replace-match (downcase itemno) nil nil curitem)))
+                (progn
+                  (setq itemno (car (cdr (member 
+                                          (match-string 0 curitem)
+                                         roman-number-list))))
+                  (setq newitem (replace-match itemno nil nil curitem))))))
+           ((string-match "[a-yA-Y]" curitem)
+            (progn
+              (setq itemno (1+
+                            (string-to-char
+                             (match-string 0 curitem))))
+              (setq newitem (replace-match
+                             (char-to-string itemno)
+                             nil nil curitem)))))
+     (insert (concat "\n" newitem))))
+ 
+ (defun rst-insert-list (itemno)
+   "Insert a list item at the current point.
+ 
+ The command can insert a new list or a continuing list. When it is called at a 
+ non-list line, it will promote to insert new list. When it is called at a list 
+ line, it will insert a list with the same list style. 
+ 
+ 1. When inserting a new list: 
+ 
+ User is asked to select the item style first, for example (a), i), +. Use TAB 
+ for completition and choices.
+ 
+  (a) If user selects bullets or #, it's just added. 
+  (b) If user selects enumerates, a further prompt is given. User need to input a 
+ starting item, for example 'e' for 'A)' style. 
+ 
+ The position of the new list is arranged according whether or not the current line 
+ and the previous line are blank lines.
+ 
+ 2. When continuing a list, one thing need to be noticed: 
+ 
+ List style alphabetical list, such as 'a.', and roman numerical list, such as 'i.', 
+ have some overlapping items, for example 'v.' The function can deal with the 
+ problem elegantly in most situations. But when those overlapped list proceeded 
+ by a blank line, it is hard to determine which type to use automatically. The 
+ function uses roman numerical list defaultly. If you want alphabetical list, just 
+ use a prefix (\\[universal-argument]).
+ "
+   (interactive "P")
+   (if (equal (rst-list-match-string rst-re-items) "")
+       (if (null current-prefix-arg)
+           (rst-insert-list-new-bullet)
+         (rst-insert-list-new-item itemno))
+     (rst-insert-list-continue)))
+ 
+ ;==============
+ 
  (defun rst-find-pfx-in-region (beg end pfx-re)
    "Find all the positions of prefixes in region between BEG and END.
  This is used to find bullets and enumerated list items.  PFX-RE
*************** is a regular expression for matching the
*** 1531,1563 ****
  	(forward-line 1)) )
      (nreverse pfx)))
  
- (defvar rst-re-bullets
-   (format "\\([%s][ \t]\\)[^ \t]" (regexp-quote (concat rst-bullets)))
-   "Regexp for finding bullets.")
- 
- ;; (defvar rst-re-enumerations
- ;;   "\\(\\(#\\|[0-9]+\\)\\.[ \t]\\)[^ \t]"
- ;;   "Regexp for finding bullets.")
- 
- (defvar rst-re-items
-   (format "\\(%s\\|%s\\)[^ \t]"
- 	  (format "[%s][ \t]" (regexp-quote (concat rst-bullets)))
- 	  "\\(#\\|[0-9]+\\)\\.[ \t]")
-   "Regexp for finding bullets.")
- 
- (defvar rst-preferred-bullets
-   '(?- ?* ?+)
-   "List of favourite bullets to set for straightening bullets.")
- 
  (defun rst-straighten-bullets-region (beg end)
    "Make all the bulleted list items in the region consistent.
  The region is specified between BEG and END.  You can use this
  after you have merged multiple bulleted lists to make them use
  the same/correct/consistent bullet characters.
  
! See variable `rst-preferred-bullets' for the list of bullets to
! adjust.  If bullets are found on levels beyond the
! `rst-preferred-bullets' list, they are not modified."
    (interactive "r")
  
    (let ((bullets (rst-find-pfx-in-region beg end
--- 1792,1806 ----
  	(forward-line 1)) )
      (nreverse pfx)))
  
  (defun rst-straighten-bullets-region (beg end)
    "Make all the bulleted list items in the region consistent.
  The region is specified between BEG and END.  You can use this
  after you have merged multiple bulleted lists to make them use
  the same/correct/consistent bullet characters.
  
! See variable `rst-bullets' for the list of bullets to adjust.  
! If bullets are found on levels beyond the `rst-bullets' list, 
! they are not modified."
    (interactive "r")
  
    (let ((bullets (rst-find-pfx-in-region beg end
*************** adjust.  If bullets are found on levels
*** 1576,1582 ****
      (let ((poslist ()))                 ; List of (indent . positions).
        (maphash (lambda (x y) (push (cons x y) poslist)) levtable)
  
!       (let ((bullets rst-preferred-bullets))
          (dolist (x (sort poslist 'car-less-than-car))
            (when bullets
              ;; Apply the characters.
--- 1819,1825 ----
      (let ((poslist ()))                 ; List of (indent . positions).
        (maphash (lambda (x y) (push (cons x y) poslist)) levtable)
  
!       (let ((bullets rst-bullets))
          (dolist (x (sort poslist 'car-less-than-car))
            (when bullets
              ;; Apply the characters.
*************** adjust.  If bullets are found on levels
*** 1586,1591 ****
--- 1829,1837 ----
                (insert (string (car bullets))))
              (setq bullets (cdr bullets))))))))
  
+ ;=================================================
+ 
+ 
  (defun rst-rstrip (str)
    "Strips the whitespace at the end of string STR."
    (string-match "[ \t\n]*\\'" str)
*************** file-write hook to always make it up-to-
*** 1912,1918 ****
    (let ((p (point)))
      (save-excursion
        (when (rst-toc-insert-find-delete-contents)
!         (insert "\n    ")
  	(rst-toc-insert)
  	))
      ;; Somehow save-excursion does not really work well.
--- 2158,2164 ----
    (let ((p (point)))
      (save-excursion
        (when (rst-toc-insert-find-delete-contents)
!         (insert "\n   ")
  	(rst-toc-insert)
  	))
      ;; Somehow save-excursion does not really work well.
*************** details check the Rst Faces Defaults gro
*** 2823,2829 ****
        1 rst-block-face)
       ;; `Enumerated Lists`_
       (list
!       (concat re-bol "\\((?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCMivxlcm]+\\)[.)]"
  	      re-blksep1 "\\)")
        1 rst-block-face)
       ;; `Definition Lists`_ FIXME: missing
--- 3069,3075 ----
        1 rst-block-face)
       ;; `Enumerated Lists`_
       (list
!       (concat re-bol "\\((?\\(#\\|[0-9]+\\|[A-Za-z]\\|[IVXLCDMivxlcdm]+\\)[.)]"
  	      re-blksep1 "\\)")
        1 rst-block-face)
       ;; `Definition Lists`_ FIXME: missing
*************** entered.")
*** 3189,3194 ****
--- 3435,4067 ----
  	(set-match-data mtc)
  	t))))
  
+ \f
+  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ;; directives and hyperlinks.
+ 
+ ;===== directive type list and command =====
+ 
+ (defvar rst-directive-type-alist
+   '(("definition" . rst-insert-definition) 
+     ("field" . rst-insert-field) 
+     ("admonition" . rst-insert-admonition)
+     ("image" . rst-insert-image) 
+     ("figure" . rst-insert-figure)
+     ("topic" . rst-insert-topic) 
+     ("sidebar" . rst-insert-sidebar) 
+     ("line-block" . rst-insert-line-block) 
+     ("parsed-literal" . rst-insert-parsed-literal) 
+     ("rubric" . rst-insert-rubric) 
+     ("epigraph" . rst-insert-epigraph) 
+     ("highlights" . rst-insert-highlights) 
+     ("pull-quote" . rst-insert-pull-quote) 
+     ("compound" . rst-insert-compound) 
+     ("container" . rst-insert-container) 
+     ("table" . rst-insert-table) 
+     ("csv-table" . rst-insert-csv-table)
+     ("list-table" . rst-insert-list-table)
+     ("contents" . rst-insert-contents) 
+     ("sectnum" . rst-insert-sectnum) 
+     ("replace" . rst-insert-replace) 
+     ("unicode" . rst-insert-unicode) 
+     ("date" . rst-insert-date) 
+     ("include" . rst-insert-include) 
+     ("raw" . rst-insert-raw))
+   "List of directive inserting functions of directive types.")
+ 
+ (defvar rst-directive-types
+   '("definition" "field" "admonition" 
+     "image" "figure" 
+     "topic" "sidebar" "line-block" "parsed-literal" "rubric" "epigraph" 
+     "highlights" "pull-quote" "compound" "container" 
+     "table" "csv-table" "list-table"
+     "contents" "sectnum" "include" "raw"
+     "replace" "unicode" "date"
+ )
+   "List of directive types")
+ 
+ (defvar rst-directive-option-list
+   '(("definition" rst-option-definition t) 
+     ("field" rst-option-field t) 
+     ("admonition" rst-option-admonition nil)
+     ("image" rst-option-image nil) 
+     ("figure" rst-option-figure t)
+     ("topic" nil t) 
+     ("sidebar" rst-option-sidebar t)
+     ("line-block" nil t) 
+     ("parsed-literal" nil t) 
+     ("rubric" nil nil) 
+     ("epigraph" nil t) 
+     ("highlights" nil t) 
+     ("pull-quote" nil t) 
+     ("compound" nil t) 
+     ("container" nil t) 
+     ("table" nil t) 
+     ("csv-table" rst-option-csv-table t)
+     ("list-table" rst-option-list-table t)
+     ("contents" rst-contents-option nil) 
+     ("sectnum" rst-sectnum-option nil) 
+     ("replace" nil nil) 
+     ("unicode" rst-option-unicode nil) 
+     ("date" nil nil) 
+     ("include" rst-include-option nil) 
+     ("raw" rst-option-raw t))
+   "List of option functions of directive types.")
+ 
+ (defun rst-add-directive-type (type directfunc optalist content)
+   "Adding new directive to directive alist and completion list.
+ 
+ Use the following way to add directive type.
+ 
+   (rst-add-directive-type \"definition\" 
+                           'rst-insert-definition
+                           'rst-directive-options 
+                           'content-presence-boolean)
+ "
+   (add-to-list 'rst-directive-types type)
+   (add-to-list 'rst-directive-type-alist (cons type directfunc))
+   (add-to-list 'rst-directive-option-list (list type optalist content)))
+ 
+ (defun rst-add-directives (directlist)
+   "Meta function of add directives. 
+ 
+ Elements of directives should arranged as 
+ 
+    (type funciton option-list content-boolean). 
+ "
+   (dolist (direct directlist)
+     (eval (cons 'rst-add-directive-type direct))))
+ 
+ (defun rst-insert-directive ()
+   "Meta-function of all directives."
+   (interactive)
+   (let (type optlist content optorder)
+     (setq type (completing-read "Providing directive type: " rst-directive-types))
+     (funcall (cdr (assoc type rst-directive-type-alist)))
+     (setq optlist (eval (car (cdr (assoc type rst-directive-option-list)))))
+     (setq content (eval (cadr (cdr (assoc type rst-directive-option-list)))))
+     (if optlist
+         (progn
+           (if (not optorder)
+               (progn
+                 (setq optorder 1)
+                 (insert "   ")))
+           (while (y-or-n-p "Set directive option(s)? ")
+             (rst-option-directive optlist))))
+     (if content
+         (newline-and-indent)
+       (newline-and-indent))))
+ 
+ ;==== directive and list definitions ====
+ 
+ ;--- list looks like directive ---
+ 
+ (defun rst-insert-definition ()
+   "Insert a definition list"
+   (interactive)
+   (let (term classifiers classel)
+     (setq term (read-string "Providing the definition's term: "))
+     (setq classifiers (read-string "Providing classifier(s) (if many, seperated by ', '): "))
+     (if (equal classifiers "")
+         (insert term "\n    ")
+       (progn
+         (setq classifiers (split-string classifiers ", "))
+         (dolist (tmpclass classifiers)
+           (setq classel (concat classel " : " tmpclass)))
+         (insert term classel "\n    ")))))
+ 
+ (defun rst-insert-field ()
+   "Insert a field list."
+   (interactive)
+   (let (field value)
+     (setq field (read-string "Providing field: "))
+     (save-excursion
+       (beginning-of-line)
+       (insert (concat ":" field ": ")))))
+ 
+ ;--- function for defining directives ---
+ 
+ (defun rst-insert-directive-type (type &optional argument)
+   "Insert the first line of directive"
+   (insert (concat ".. " type ":: " argument))
+   (newline-and-indent))
+ 
+ (defun rst-insert-directive-option (option &optional value)
+   "Insert an option line of directive"
+   (insert (concat ":" option ": " value)))
+ 
+ (defun rst-insert-option ()
+   "Insert a directive option."
+   (interactive)
+   (let (option value)
+     (save-excursion
+       (re-search-backward "\\.\\. \\sw+::")
+       (setq option (read-string "Providing directive option: "))
+       (setq value (read-string "Providing option value: "))
+       (end-of-line)
+       (newline-and-indent)
+       (insert "   ")
+       (rst-insert-directive-option option value))))
+ 
+ (defun rst-option-directive (optalist)
+   "Insert directive options in directive inserting function."
+   (let (optlist option type value)
+     (setq optlist (mapcar 'car optalist))
+     (setq option (completing-read "Providing option: " optlist))
+     (setq type (car (cdr (assoc option optalist))))
+     (setq value
+           (cond 
+            ((equal type "flag") nil)
+            ((equal type "option") (completing-read 
+                                    "Providing optional value: " 
+                                    (cadr (cdr (assoc option optalist)))))
+            ((equal type "number") (number-to-string 
+                                    (read-number "Providing numeric value: ")))
+            ((equal type "string") (read-string "Providing value: "))))
+     (rst-insert-directive-option option value)
+     (newline-and-indent)))
+ 
+ ;--- directives ---
+ 
+ (defun rst-insert-admonition ()
+   "Insert a admonition."
+   (interactive)
+   (let (admon argu)
+     (setq admon (read-string "Providing admonition type: "))
+     (setq argu (read-string "Providing admonition description: "))
+     (rst-insert-directive-type admon argu)))
+ 
+ (defun rst-insert-image ()
+   "Insert a image."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing image and its path: "))
+     (rst-insert-directive-type "image" arg)))
+ 
+ (defvar rst-option-image
+   '(("align" "option" ("top" "middle" "bottom" "left" "center" "right"))
+     ("width" "string" "300")
+     ("height" "string" "300")
+     ("scale" "number" 80)
+     ("alt" "string" "")
+     ("target" "string" "")))
+ 
+ (defun rst-insert-figure ()
+   "Insert a image."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing figure and its path: "))
+     (rst-insert-directive-type "figure" arg)))
+ 
+ (defvar rst-option-figure
+   '(("align" "option" ("left" "center" "right"))
+     ("width" "string" "300")
+     ("height" "string" "300")
+     ("scale" "number" 80)
+     ("figwidth" "string" "350")
+     ("alt" "string" "")
+     ("target" "string" "")))
+ 
+ (defun rst-insert-topic ()
+   "Insert a topic."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing topic title: "))
+     (rst-insert-directive-type "topic" arg)))
+ 
+ (defun rst-insert-sidebar ()
+   "Insert a sidebar."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing sidebar title: "))
+     (rst-insert-directive-type "sidebar" arg)))
+ 
+ (defvar rst-option-sidebar
+ '(("subtitle" "string" "")))
+ 
+ (defun rst-insert-line-block ()
+   "Insert a line block."
+   (interactive)
+   (rst-insert-directive-type "line-block"))
+ 
+ (defun rst-insert-parsed-literal ()
+   "Insert a parsed literal."
+   (interactive)
+   (rst-insert-directive-type "parsed-literal"))
+ 
+ (defun rst-insert-rubric ()
+   "Insert a rubric title."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing rubric title: "))
+     (rst-insert-directive-type "rubric" arg)))
+ 
+ (defun rst-insert-epigraph ()
+   "Insert a epigraph."
+   (interactive)
+   (rst-insert-directive-type "epigraph"))
+ 
+ (defun rst-insert-highlights ()
+   "Insert a highlights."
+   (interactive)
+   (rst-insert-directive-type "highlights"))
+ 
+ (defun rst-insert-pull-quote ()
+   "Insert a pull quote."
+   (interactive)
+   (rst-insert-directive-type "pull-quote"))
+ 
+ (defun rst-insert-compound ()
+   "Insert a compound."
+   (interactive)
+   (rst-insert-directive-type "compound"))
+ 
+ (defun rst-insert-container ()
+   "Insert a container."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing container title: "))
+     (rst-insert-directive-type "container" arg)))
+ 
+ (defun rst-insert-table ()
+   "Insert a table."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing table title: "))
+     (rst-insert-directive-type "table" arg)))
+ 
+ (defun rst-insert-csv-table ()
+   "Insert a table."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing table title: "))
+     (rst-insert-directive-type "csv-table" arg)))
+ 
+ (defvar rst-option-csv-table
+ '(("widths" "string" "")
+   ("header-rows" "number" 0)
+   ("stub-columns" "number" 0)
+   ("header" "string" "")
+   ("file" "string" "")
+   ("url" "string" "")
+   ("encoding" "string" "")
+   ("delim" "string" "")
+   ("quote" "string" "")
+   ("keepspace" "flag" nil)
+   ("escape" "string" "")))
+ 
+ (defun rst-insert-list-table ()
+   "Insert a table."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing table title: "))
+     (rst-insert-directive-type "list-table" arg)))
+ 
+ (defvar rst-option-list-table
+ '(("widths" "string" "")
+   ("header-rows" "number" 0)
+   ("stub-columns" "number" 0)))
+ 
+ (defun rst-insert-contents ()
+   "Insert a contents."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing contents title: "))
+     (rst-insert-directive-type "contents" arg)))
+ 
+ (defvar rst-option-contents
+ '(("backlinks" "option" ("entry" "top" "none"))
+   ("depth" "number" 2)
+   ("local" "flag" nil)))
+ 
+ (defun rst-insert-sectnum ()
+   "Set section-autonumbering."
+   (interactive)
+   (rst-insert-directive-type "sectnum"))
+ 
+ (defvar rst-option-sectnum
+ '(("prefix" "string" "")
+   ("suffix" "string" "")
+   ("depth" "number" 2)
+   ("start" "number" 1)))
+ 
+ (defun rst-insert-replace ()
+   "Insert the head of word replace."
+   (interactive)
+   (let (tag)
+     (setq tag (read-string "Providing replaced word: "))
+     (rst-insert-directive-type (concat "|" tag "| replace"))))
+ 
+ (defun rst-insert-unicode ()
+   "Insert unicode replacement."
+   (interactive)
+   (let (tag)
+     (setq tag (read-string "Providing unicode string: "))
+     (rst-insert-directive-type (concat "|" tag "| unicode"))))
+ 
+ (defvar rst-option-unicode
+   '(("ltrim" "flag" nil)
+     ("rtrim" "flag" nil)
+     ("trim" "flag" nil)))
+ 
+ (defun rst-insert-date ()
+   "Insert date or time."
+   (interactive)
+   (let (type value)
+     (setq type (completing-read "Insert date or time? " '("date" "time")))
+     (cond
+      ((equal type "date") 
+       (setq value (read-string "Providing date format: " nil nil "%Y-%m-%d")))
+      ((equal type "time") 
+       (setq value (read-string "Providing time format: " nil nil "%H:%M"))))
+     (rst-insert-directive-type (concat "|" type "| date") value)))
+ 
+ (defun rst-insert-include ()
+   "Insert an external file."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing file path: "))
+     (rst-insert-directive-type "include" arg)))
+ 
+ (defvar rst-option-include
+   '(("start-after" "string" "")
+     ("end-before" "string" "")
+     ("encoding" "string" "")
+     ("literal" "flag" nil)))
+ 
+ (defun rst-insert-raw ()
+   "Insert raw data."
+   (interactive)
+   (let (arg)
+     (setq arg (read-string "Providing raw data type: "))
+     (rst-insert-directive-type "raw" arg)))
+ 
+ (defvar rst-option-raw
+   '(("file" "string" "")
+     ("url" "string" "")
+     ("encoding" "string" "")))
+ 
+ 
+ ;==== links ====
+ 
+ ;--- link inserting ---
+ 
+ (defvar rst-link-type-alist
+   '(("hyperlink" . rst-insert-inline-link) 
+     ("footnote" . rst-insert-footnote) 
+     ("citation" . rst-insert-citation))
+   "List of link types.")
+ 
+ (defvar rst-link-type
+   '("hyperlink" "footnote" "citation")
+   "List of link types for completion")
+ 
+ (defun rst-insert-link ()
+   "Meta-function of all directives."
+   (interactive)
+   (let (type)
+     (setq type (completing-read "Providing link type: " rst-link-type))
+     (funcall (cdr (assoc type rst-link-type-alist)))))
+ 
+ (defun rst-insert-inline-link ()
+   "Insert a inline link with both target and reference."
+   (interactive)
+   (let (link target reference)
+     (setq link (read-string "Providing link name: "))
+     (if (string-match " " link)
+         (progn
+           (setq target (concat "`" link "`_"))
+           (setq reference (concat ".. _`" link "`: ")))
+       (progn
+         (setq target (concat link "_"))
+         (setq reference (concat ".. _" link ": "))))
+     (save-excursion
+       (if (equal (char-before) (string-to-char " "))
+           (insert target " ")
+         (insert (concat " " target " ")))
+       (end-of-line)
+       (insert (concat "\n\n" reference)))))
+ 
+ (defun rst-insert-footnote ()
+   "Insert a inline footnote with both target and reference."
+   (interactive)
+   (let (footnote target reference)
+     (setq footnote (read-string "Providing footnote name: "))
+     (setq target (concat "[#" footnote "]_"))
+     (setq reference (concat ".. [#" footnote "] "))
+     (save-excursion
+       (if (equal (char-before) (string-to-char " "))
+           (insert target " ")
+         (insert (concat " " target " ")))
+       (end-of-line)
+       (insert (concat "\n\n" reference)))))
+ 
+ (defun rst-insert-citation ()
+   "Insert a inline citation with both target and reference."
+   (interactive)
+   (let (citation target reference)
+     (setq citation (read-string "Providing citation name: "))
+     (setq target (concat "[" citation "]_"))
+     (setq reference (concat ".. [" citation "] "))
+     (save-excursion
+       (if (equal (char-before) (string-to-char " "))
+           (insert target " ")
+         (insert (concat " " target " ")))
+       (end-of-line)
+       (insert (concat "\n\n" reference)))))
+ 
+ ;--- link jumping ---
+ 
+ (defun rst-hyper-link-reference-match ()
+   "Match link target around the point."
+   (let (link reference target)
+     (save-excursion
+       (if (search-forward "_" 
+                           (save-excursion 
+                             (forward-sentence) 
+                             (point)) 
+                           t 1)
+           (progn
+             (backward-char)
+             (unless (equal (char-before) ?\\)
+               (if (equal (char-before) ?`)
+                   (progn
+                     (forward-char)
+                     (re-search-backward "`[[:alnum:][:punct:][:space:]]+`_" 
+                                         (save-excursion 
+                                           (search-backward "`" nil t 2) 
+                                           (point)) 
+                                         t)
+                     (setq reference (match-string 0))
+                     (setq link (substring reference 0 -1)))
+                 (progn
+                   (forward-char)
+                   (re-search-backward " \\sw+_" 
+                                       (save-excursion 
+                                         (search-backward " ") 
+                                         (point)) 
+                                       t)
+                   (setq reference (match-string 0))
+                   (setq link (substring reference 1 -1)))))
+             (setq target (concat ".. _" link ":")))))
+     (list reference target)))
+ 
+ (defun rst-link-jump-to-target ()
+   "Jump from intertext link reference to link target."
+   (interactive)
+   (let ((target (elt (rst-hyper-link-reference-match) 1)))
+     (when (save-excursion
+             (goto-char (point-min))
+             (search-forward target))
+       (goto-char (point-min))
+       (search-forward target))))
+ 
+ (defun rst-link-jump-within-references ()
+   "Jump within references of an intertext link, if exist."
+   (interactive)
+   (let ((reference (elt (rst-hyper-link-reference-match) 0)))
+     (if (save-excursion
+           (search-forward reference nil t 1))
+         (progn
+           (search-forward reference nil t 1)
+           (backward-char 1))
+       (when (y-or-n-p "No link reference behind. Search from the beginning?")
+         (goto-char (point-min))
+         (search-forward reference nil t 1)
+         (backward-char 1)))))
+ 
+ (defun rst-hyper-link-target-match ()
+   "Match link reference at the target line."
+   (let (link reference target)
+     (save-excursion
+       (when (search-backward ".. _" (line-beginning-position) t 1)
+         (re-search-forward 
+          "^\\.\\. _`?[[:alnum:][:punct:][:space:]]+`?: " 
+          (line-end-position) t 1)
+         (setq target (match-string 0))))
+     (setq link (substring target 4 -2))
+     (if (equal (substring link 0 1) "`")
+         (setq reference (concat link "_"))
+       (setq reference (concat " " link "_")))
+     (list reference target)))
+ 
+ (defun rst-link-jump-to-reference ()
+   "Jump from intertext link target to link reference."
+   (interactive)
+   (let ((reference (elt (rst-hyper-link-target-match) 0)))
+     (when (save-excursion
+             (goto-char (point-max))
+             (search-backward reference))
+       (goto-char (point-max))
+       (search-backward reference))))
+ 
+ ;--- footnote and citation ---
+ 
+ (defun rst-footnote-citation-reference-match ()
+   "Match footnote or citation reference around the point."
+   (let (link reference target)
+     (save-excursion
+       (when (search-forward "]_" 
+                             (save-excursion 
+                               (forward-sentence) 
+                               (point)) 
+                             t 1)
+         (re-search-backward "\\[[[:alnum:][:punct:][:space:]]+\\]_" 
+                             (save-excursion 
+                               (search-backward "[" nil t 1) 
+                               (point)) 
+                             t)
+         (setq reference (match-string 0))))
+     (setq link (substring reference 1 -2))
+     (setq target (concat ".. [" link "]"))
+     (list reference target)))
+ 
+ (defun rst-footnote-citation-target-match ()
+   "Match footnote or citation reference at the target line."
+   (let (link reference target)
+     (save-excursion
+       (when (search-backward ".. [" (line-beginning-position) t 1)
+         (re-search-forward 
+          "^\\.\\. \\[[[:alnum:][:punct:][:space:]]+\\] " 
+          (line-end-position) t 1)
+         (setq target (match-string 0))))
+     (setq link (substring target 4 -2))
+     (setq reference (concat " [" link "]_"))
+     (list reference target)))
+ 
+ (defun rst-footnote-citation-jump-to-target ()
+   "Jump from footnote or citation reference to target."
+   (interactive)
+   (let ((target (elt (rst-footnote-citation-reference-match) 1)))
+     (when (save-excursion
+             (goto-char (point-min))
+             (search-forward target))
+       (goto-char (point-min))
+       (search-forward target))))
+ 
+ (defun rst-footnote-citation-jump-within-references ()
+   "Jump within references of an footnote or citation, if exist."
+   (interactive)
+   (let ((reference (elt (rst-footnote-citation-reference-match) 0)))
+     (if (save-excursion
+           (search-forward reference nil t 1))
+         (progn
+           (search-forward reference nil t 1)
+           (backward-char 1))
+       (when (y-or-n-p "No link reference behind. Search from the beginning?")
+         (goto-char (point-min))
+         (search-forward reference nil t 1)
+         (backward-char 2)))))
+ 
+ (defun rst-footnote-citation-jump-to-reference ()
+   "Jump from footnote or citation target to reference."
+   (interactive)
+   (let ((reference (elt (rst-footnote-citation-target-match) 0)))
+     (when (save-excursion
+             (goto-char (point-max))
+             (search-backward reference))
+       (goto-char (point-max))
+       (search-backward reference))))
  
  
  \f

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

* bug#6531: patch for rst.el updated (patch format revised)
  2010-06-28 13:58 bug#6531: patch for rst.el updated (patch format revised) Wei-Wei Guo
@ 2012-04-12 17:41 ` Lars Magne Ingebrigtsen
  2012-04-12 20:30 ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Lars Magne Ingebrigtsen @ 2012-04-12 17:41 UTC (permalink / raw)
  To: Wei-Wei Guo; +Cc: 6531

Wei-Wei Guo <wwguocn@gmail.com> writes:

> I updated my patch for rst.el of Emacs 23. Here are the previous changes:
>
>    http://debbugs.gnu.org/cgi/bugreport.cgi?bug=1610
>
> The update including:
>
> - Insert bullet list by 'M-Enter'.
> - Insert number list "#." by 'M-Enter' with any prefix.
> - Insert number list of a specific number of various styles by
> M-Enter" with a number prefix.
> - Insert directive by 'C-c C-d'.
> - Insert directive option by 'C-c C-o'.
> - Remove the dependency on a2r.el. Now all the patched codes are from mine.

I don't use restructured text, so I can't really test this, but looking
at the code, it looks good to me.

The patch no longer applies cleanly, but the conflicts are pretty minor.

Does any rst.el users have an opinion on whether to apply this patch to
trunk or not?

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/





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

* bug#6531: patch for rst.el updated (patch format revised)
  2010-06-28 13:58 bug#6531: patch for rst.el updated (patch format revised) Wei-Wei Guo
  2012-04-12 17:41 ` Lars Magne Ingebrigtsen
@ 2012-04-12 20:30 ` Stefan Monnier
  2012-04-13  3:13   ` Martin Blais
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2012-04-12 20:30 UTC (permalink / raw)
  To: Wei-Wei Guo; +Cc: Martin Blais, 6531, Stefan Merten, David Goodger

> The update including:

> - Insert bullet list by 'M-Enter'.
> - Insert number list "#." by 'M-Enter' with any prefix.
> - Insert number list of a specific number of various styles by 'M-Enter" with a number prefix.
> - Insert directive by 'C-c C-d'.
> - Insert directive option by 'C-c C-o'.
> - Remove the dependency on a2r.el. Now all the patched codes are from mine.

> Hope it's helpful.

I'd like to hear the opinion of rst.el's maintainers as well.
Additionally I have a few questions/comments:

> -    (define-key map [(control c) (control a)] 'rst-adjust)
> -    (define-key map [(control c) (control ?=)] 'rst-adjust)
> +    ;(define-key map [(control c) (control a)] 'rst-adjust)
> +    ;(define-key map [(control c) (control ?=)] 'rst-adjust)

A single ";" is used for comments at the end of line after code.  If you
try to hit TAB you'll see that the get indented in a way you won't like
for the above code.

So please use ";;" instead when commenting out a whole line.   If you
use "<select-line> followed by M-;", it'll be done automatically for you.

This said, I wonder why you comment this out.  It seems unrelated to the
changes you mention a being part of your update.

> -    (define-key map [(control c) (control h)] 'rst-display-decorations-hierarchy)
> +    (define-key map [(control c) (control t)] 'rst-display-decorations-hierarchy)

Same here, why change the binding?

> -    (define-key map [(control c) (control n)] 'rst-forward-section)
> -    (define-key map [(control c) (control p)] 'rst-backward-section)
> +    (define-key map [(meta n)] 'rst-forward-section)
> +    (define-key map [(meta p)] 'rst-backward-section)

Idem.  Plus many more.  You've made a lot of changes to the keymap that
don't seem related.  Please describe them at least, and explain why you
think they're needed or useful.

> +    ;; Inserts bullet list or enumeration list.
> +    (define-key map [(meta return)] 'rst-insert-list)

This is the one I expected to see, yes.

> +    ;; Inserts definition list.
> +    ;(define-key map [(control c) t] 'rst-insert-definition)

"C-c followed by a letter" are some of the very few bindings that are
reserved for the user and that major modes should hence not use themselves.

> +  (if (save-excursion
> +        (beginning-of-line)
> +        (looking-at "^[ \t]*$"))
> +      (if (save-excursion
> +            (forward-line -1)
> +            (looking-at "^[ \t]*$"))
> +          (insert (concat newitem " "))
> +        (insert (concat "\n" newitem " ")))
> +    (progn 
> +      (insert (concat "\n\n" newitem " ")))))

CSE simplifies it to:

     (insert (if (save-excursion
                   (beginning-of-line)
                   (looking-at "^[ \t]*$"))
                 (if (save-excursion
                       (forward-line -1)
                       (looking-at "^[ \t]*$"))
                     nil "\n")
               "\n\n")
             newitem " "))

> +  (let (itemstyle)
> +    (setq itemstyle "-")
> +    (rst-insert-list-pos itemstyle)))

This whole code simplifies to: (rst-insert-list-pos "-")

> +  (let (itemstyle itemfirst)
> +    (setq itemstyle (completing-read "Providing perfered item (default '#.'): "
> +                                     rst-initial-items nil t nil nil "#."))

The form: (let (var) (setq var <foo>) ...)
is much better written (let ((var <foo>)) ...)
So the above would be written:

  (let ((itemstyle (completing-read "Providing perfered item (default '#.'): "
                                    rst-initial-items nil t nil nil "#."))
        itemfirst)

> +    (when (string-match "[aA1Ii]" itemstyle)
> +      (setq itemfirst (match-string 0 itemstyle))
> +      (cond ((equal itemfirst "A") 
> +             (setq itemstyle (replace-match (nth itemno letter-list) 
> +                                            nil nil itemstyle)))
> +            ((equal itemfirst "a") 
> +             (setq itemstyle (replace-match (downcase (nth itemno letter-list)) 
> +                                            nil nil itemstyle)))
> +            ((equal itemfirst "I") 
> +             (setq itemstyle (replace-match (nth itemno roman-number-list) 
> +                                            nil nil itemstyle)))
> +            ((equal itemfirst "i") 
> +             (setq itemstyle (replace-match (downcase (nth itemno roman-number-list)) 
> +                                            nil nil itemstyle)))
> +            ((equal itemfirst "1") 
> +             (setq itemstyle (replace-match (number-to-string (1+ itemno)) 
> +                                            nil nil itemstyle)))
> +            ))

Again, better hoist those "(setq itemstyle (replace-match ...)" outside
of the cond.  And you can replace the `cond' with a `case', which will
also save you the trouble of naming `itemfirst':

        (setq itemstyle
              (replace-match (case (aref itemstyle (match-beginning 0))
                               (?A (nth itemno letter-list))
                               (?a (downcase (nth itemno letter-list)))
                               (?I (nth itemno roman-number-list))
                               (?i (downcase (nth itemno roman-number-list)))
                               (?1 (number-to-string (1+ itemno)))
                               (t itemstyle)) ;; Leave it alone?
                             nil nil itemstyle))

> +  (let (matched)
> +    (save-excursion
> +      (end-of-line)
> +      (if (re-search-backward reg (line-beginning-position) t)
> +          (setq matched (match-string 0))
> +        (setq matched "")))
> +    matched))

Simplifications:

     (let (matched)
       (save-excursion
         (end-of-line)
         (setq matched (if (re-search-backward reg (line-beginning-position) t)
                           (match-string 0)
                         "")))
       matched))
=>
     (let (matched)
       (save-excursion
         (end-of-line)
         (setq matched (if (re-search-backward reg (line-beginning-position) t)
                           (match-string 0)
                         ""))
         matched)))
=>
     (let (matched)
       (save-excursion
         (end-of-line)
         (if (re-search-backward reg (line-beginning-position) t)
             (match-string 0)
           ""))))
=>
     (save-excursion
       (end-of-line)
       (if (re-search-backward reg (line-beginning-position) t)
           (match-string 0)
         "")))

BTW, I'm curious: is there a particular reason why you do the
match backward?  There's nothing fundamentally wrong with it, but regexp
matching backward behaves slightly differently and is marginally less
efficient, so if there's no particular reason I'd suggest to use
a forward match.

> +                               (setq previtem (rst-list-match-string rst-re-enumerates))

Stay within 80 columns please.

> +                 (progn
> +                   (setq itemno (car (cdr (member 
> +                                           (match-string 0 (upcase curitem)) 
> +                                           roman-number-list))))
> +                   (setq newitem (replace-match (downcase itemno) nil nil curitem)))

Better do

                    (let ((itemno (car (cdr (member
                                             (match-string 0 (upcase curitem)) 
                                             roman-number-list)))))
                      (setq newitem (replace-match (downcase itemno)
                                                   nil nil curitem)))

If you make this change in all branches, you'll see that you can again
hoist the (setq newitem ...) out of the `cond'.

> -(defvar rst-preferred-bullets
> -  '(?- ?* ?+)
> -  "List of favourite bullets to set for straightening bullets.")

Using just rst-bullets instead of rst-preferred-bullets sounds like
a good idea (to my non-rst-user-eyes anyway), but it should be mentioned
in your description of the changes.

> @@ -1912,7 +2158,7 @@
>    (let ((p (point)))
>      (save-excursion
>        (when (rst-toc-insert-find-delete-contents)
> -        (insert "\n    ")
> +        (insert "\n   ")
>  	(rst-toc-insert)
>  	))
>      ;; Somehow save-excursion does not really work well.

Same here: document and explain why you made this change.

> +(defvar rst-directive-type-alist
> +  '(("definition" . rst-insert-definition) 
> +    ("field" . rst-insert-field) 
> +    ("admonition" . rst-insert-admonition)
> +    ("image" . rst-insert-image) 
> +    ("figure" . rst-insert-figure)
> +    ("topic" . rst-insert-topic) 
> +    ("sidebar" . rst-insert-sidebar) 
> +    ("line-block" . rst-insert-line-block) 
> +    ("parsed-literal" . rst-insert-parsed-literal) 
> +    ("rubric" . rst-insert-rubric) 
> +    ("epigraph" . rst-insert-epigraph) 
> +    ("highlights" . rst-insert-highlights) 
> +    ("pull-quote" . rst-insert-pull-quote) 
> +    ("compound" . rst-insert-compound) 
> +    ("container" . rst-insert-container) 
> +    ("table" . rst-insert-table) 
> +    ("csv-table" . rst-insert-csv-table)
> +    ("list-table" . rst-insert-list-table)
> +    ("contents" . rst-insert-contents) 
> +    ("sectnum" . rst-insert-sectnum) 
> +    ("replace" . rst-insert-replace) 
> +    ("unicode" . rst-insert-unicode) 
> +    ("date" . rst-insert-date) 
> +    ("include" . rst-insert-include) 
> +    ("raw" . rst-insert-raw))
> +  "List of directive inserting functions of directive types.")
> +
> +(defvar rst-directive-types
> +  '("definition" "field" "admonition" 
> +    "image" "figure" 
> +    "topic" "sidebar" "line-block" "parsed-literal" "rubric" "epigraph" 
> +    "highlights" "pull-quote" "compound" "container" 
> +    "table" "csv-table" "list-table"
> +    "contents" "sectnum" "include" "raw"
> +    "replace" "unicode" "date"
> +)
> +  "List of directive types")

Isn't it better to define is as (mapcar #'car rst-directive-type-alist)?

> +(defvar rst-directive-option-list
> +  '(("definition" rst-option-definition t) 
> +    ("field" rst-option-field t) 
> +    ("admonition" rst-option-admonition nil)
> +    ("image" rst-option-image nil) 
> +    ("figure" rst-option-figure t)
> +    ("topic" nil t) 
> +    ("sidebar" rst-option-sidebar t)
> +    ("line-block" nil t) 
> +    ("parsed-literal" nil t) 
> +    ("rubric" nil nil) 
> +    ("epigraph" nil t) 
> +    ("highlights" nil t) 
> +    ("pull-quote" nil t) 
> +    ("compound" nil t) 
> +    ("container" nil t) 
> +    ("table" nil t) 
> +    ("csv-table" rst-option-csv-table t)
> +    ("list-table" rst-option-list-table t)
> +    ("contents" rst-contents-option nil) 
> +    ("sectnum" rst-sectnum-option nil) 
> +    ("replace" nil nil) 
> +    ("unicode" rst-option-unicode nil) 
> +    ("date" nil nil) 
> +    ("include" rst-include-option nil) 
> +    ("raw" rst-option-raw t))
> +  "List of option functions of directive types.")

I'd suggest to merge this with rst-directive-type-alist (i.e. instead
of having each element of the form (TYPE OPTLIST CONTENT), it should be
(TYPE INSERT-FUNCTION OPTLIST CONTENT).

> +(defun rst-add-directive-type (type directfunc optalist content)
> +  "Adding new directive to directive alist and completion list.
> +
> +Use the following way to add directive type.
> +
> +  (rst-add-directive-type \"definition\" 
> +                          'rst-insert-definition
> +                          'rst-directive-options 
> +                          'content-presence-boolean)"

My above proposed change, along with the elimination of
rst-directive-types means you can just use

  (add-to-list 'rst-directive-alist
               '("definition" rst-insert-definition 'rst-directive-options t)

so you don't need a new rst-add-directive-type function.
               
> +(defun rst-add-directives (directlist)
> +  "Meta function of add directives. 
> +
> +Elements of directives should arranged as 
> +
> +   (type funciton option-list content-boolean). 
> +"
> +  (dolist (direct directlist)
> +    (eval (cons 'rst-add-directive-type direct))))

I think you can guess what I'd say here ;-)

> +(defun rst-insert-directive ()
> +  "Meta-function of all directives."
> +  (interactive)
> +  (let (type optlist content optorder)
> +    (setq type (completing-read "Providing directive type: " rst-directive-types))

The `completing-read' call should be inside the `interactive' spec.
I.e.
   (defun rst-insert-directive (type)
     "Meta-function of all directives."
     (interactive
      (list (completing-read "Providing directive type: "
                             rst-directive-types)))
     (let (...) ...)

BTW, since all your insertion functions are actually defined as
commands, you might prefer using `call-interactively' instead of
`funcall', so you can use non-trivial interactive specs in those
insertion functions.
     
> +    (if content
> +        (newline-and-indent)
> +      (newline-and-indent))))

Isn't that the same as just (newline-and-indent)?

> +(defun rst-insert-definition ()
> +  "Insert a definition list"

You need a "." at the end of the sentence.
Try C-u M-x checkdoc-current-buffer, which will give you several
suggestions for better conformance to coding conventions (of course,
these are suggestions, they may not all make sense).

> +  (let (term classifiers classel)
> +    (setq term (read-string "Providing the definition's term: "))
> +    (setq classifiers (read-string "Providing classifier(s) (if many, seperated by ', '): "))

     (let ((term (read-string "Providing the definition's term: "))
           (classifiers (read-string "Providing classifier(s) (if many, seperated by ', '): "))
           classel)

> +        (setq classifiers (split-string classifiers ", "))
> +        (dolist (tmpclass classifiers)

No need for this `setq' since you don't use classifiers afterwards.  Just:

        (dolist (tmpclass (split-string classifiers ", "))

> +  (let (field value)
> +    (setq field (read-string "Providing field: "))

Move the setq into the let.  There are many other occurrences of this
poor style.

> +(defun rst-insert-citation ()
> +  "Insert a inline citation with both target and reference."
> +  (interactive)
> +  (let (citation target reference)
> +    (setq citation (read-string "Providing citation name: "))
> +    (setq target (concat "[" citation "]_"))
> +    (setq reference (concat ".. [" citation "] "))
> +    (save-excursion
> +      (if (equal (char-before) (string-to-char " "))
> +          (insert target " ")
> +        (insert (concat " " target " ")))
> +      (end-of-line)
> +      (insert (concat "\n\n" reference)))))

If rst-insert-directive used call-interactively, I'd do:

   (defun rst-insert-citation (citation)
     "Insert a inline citation with both target and reference."
     (interactive
      (list (read-string "Providing citation name: ")))
     (let ((target (concat "[" citation "]_"))
           (reference (concat ".. [" citation "] ")))
       (save-excursion
         (insert (if (equal (char-before) ?\s) nil " ")
                 target " ")
         (end-of-line)
         (insert "\n\n" reference))))

> +                    (re-search-backward "`[[:alnum:][:punct:][:space:]]+`_" 
> +                                        (save-excursion 
> +                                          (search-backward "`" nil t 2) 
> +                                          (point)) 
> +                                        t)
> +                    (setq reference (match-string 0))

The search may fail, and you can end up with an error because
match-string will use positions from some earlier regexp match which may
even come from some unrelated buffer.


        Stefan





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

* bug#6531: patch for rst.el updated (patch format revised)
  2012-04-12 20:30 ` Stefan Monnier
@ 2012-04-13  3:13   ` Martin Blais
  2012-04-13  6:40     ` Wei-Wei Guo
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Blais @ 2012-04-13  3:13 UTC (permalink / raw)
  To: Stefan Monnier, Wei-Wei Guo; +Cc: 6531, Stefan Merten, David Goodger

On Thu, Apr 12, 2012, at 16:30, Stefan Monnier wrote:
> > The update including:
>
> > - Insert bullet list by 'M-Enter'.
> > - Insert number list "#." by 'M-Enter' with any prefix.
> > - Insert number list of a specific number of various styles by 'M-Enter" with a number prefix.
> > - Insert directive by 'C-c C-d'.
> > - Insert directive option by 'C-c C-o'.
> > - Remove the dependency on a2r.el. Now all the patched codes are from mine.
>
> > Hope it's helpful.
>
> I'd like to hear the opinion of rst.el's maintainers as well.

Holy smoke, is this a patch from 2008? Major lag in the reviewers!
Where is the link?
Is this the one?
http://debbugs.gnu.org/cgi-bin/bugreport.cgi?bug=1610

I had a very quick look at this patch--it looks fine to me (other than
the overuse of mutable locals/setq).

About the features: I personally care little about bullet insertion
functions, I find inserting them manually is good enough, but it
doesn't hurt to have them there, and others might really like them, so
I would merge it in. Thanks WeiWei! :-)

More comments below.



> Additionally I have a few questions/comments:
>
> > -    (define-key map [(control c) (control a)] 'rst-adjust)
> > -    (define-key map [(control c) (control ?=)] 'rst-adjust)
> > +    ;(define-key map [(control c) (control a)] 'rst-adjust)
> > +    ;(define-key map [(control c) (control ?=)] 'rst-adjust)
>
> A single ";" is used for comments at the end of line after code.  If you
> try to hit TAB you'll see that the get indented in a way you won't like
> for the above code.
>
> So please use ";;" instead when commenting out a whole line.   If you
> use "<select-line> followed by M-;", it'll be done automatically for you.
>
> This said, I wonder why you comment this out.  It seems unrelated to the
> changes you mention a being part of your update.

Yes.
These are needed for working in the console (no X), please bring back.




> > -    (define-key map [(control c) (control h)] 'rst-display-decorations-hierarchy)
> > +    (define-key map [(control c) (control t)] 'rst-display-decorations-hierarchy)
>
> Same here, why change the binding?

Agreed. Arbitrary rebindings aren't a good idea, just override them in
your .emacs.  I don't care too much about the choices of bindings, but
other people may have gotten used to them.




> > -    (define-key map [(control c) (control n)] 'rst-forward-section)
> > -    (define-key map [(control c) (control p)] 'rst-backward-section)
[...............]
>            (match-string 0)
>          "")))

I agree with all your comments about mutability, these should be
changed as you suggest.




> BTW, I'm curious: is there a particular reason why you do the
> match backward?  There's nothing fundamentally wrong with it, but regexp
> matching backward behaves slightly differently and is marginally less
> efficient, so if there's no particular reason I'd suggest to use
> a forward match.
>
> > +                               (setq previtem (rst-list-match-string rst-re-enumerates))
>
> Stay within 80 columns please.
>
> > +                 (progn
> > +                   (setq itemno (car (cdr (member
> > +                                           (match-string 0 (upcase curitem))
> > +                                           roman-number-list))))
> > +                   (setq newitem (replace-match (downcase itemno) nil nil curitem)))
>
> Better do
>
>                     (let ((itemno (car (cdr (member
>                                              (match-string 0 (upcase curitem))
>                                              roman-number-list)))))
>                       (setq newitem (replace-match (downcase itemno)
>                                                    nil nil curitem)))
>
> If you make this change in all branches, you'll see that you can again
> hoist the (setq newitem ...) out of the `cond'.
>
> > -(defvar rst-preferred-bullets
> > -  '(?- ?* ?+)
> > -  "List of favourite bullets to set for straightening bullets.")
>
> Using just rst-bullets instead of rst-preferred-bullets sounds like
> a good idea (to my non-rst-user-eyes anyway), but it should be mentioned
> in your description of the changes.

I think the original meaning was slightly distinct:

- `rst-bullets' was used as a set of recognized bullets, and

- `rst-preferred-bullets' used as an ordered list of normalized
  bullets to be used in the routine that fixes existing recognized
  ones.

I suppose they could be folded together... merge it in.





> > @@ -1912,7 +2158,7 @@
> >    (let ((p (point)))
> >      (save-excursion
> >        (when (rst-toc-insert-find-delete-contents)
> > -        (insert "\n    ")
> > +        (insert "\n   ")
> >  	(rst-toc-insert)
> >  	))
> >      ;; Somehow save-excursion does not really work well.
>
> Same here: document and explain why you made this change.

Yes, why?
Was probably a typo, that's an arbitrary indent.
I'd keep the same as it was (I don't care, just erring on
the side of no-change if there's no reason for it).




> > +(defvar rst-directive-type-alist
> > +  '(("definition" . rst-insert-definition)
> > +    ("field" . rst-insert-field)
> > +    ("admonition" . rst-insert-admonition)
> > +    ("image" . rst-insert-image)
[..................]
> > +"
> > +  (dolist (direct directlist)
> > +    (eval (cons 'rst-add-directive-type direct))))
>
> I think you can guess what I'd say here ;-)

Again, I agree with all of Stefan's suggestions for simplification and
setq removal, should be avoided where unnecessary.

When's the next fondue?
I love cheese.






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

* bug#6531: patch for rst.el updated (patch format revised)
  2012-04-13  3:13   ` Martin Blais
@ 2012-04-13  6:40     ` Wei-Wei Guo
  2012-04-13 12:25       ` Stefan Monnier
  2012-04-13 15:05       ` Martin Blais
  0 siblings, 2 replies; 10+ messages in thread
From: Wei-Wei Guo @ 2012-04-13  6:40 UTC (permalink / raw)
  To: Martin Blais; +Cc: 6531, David Goodger, Stefan Merten

在 2012-04-12四的 23:13 -0400,Martin Blais写道:
> On Thu, Apr 12, 2012, at 16:30, Stefan Monnier wrote:
> > > The update including:
> >
> > > - Insert bullet list by 'M-Enter'.
> > > - Insert number list "#." by 'M-Enter' with any prefix.
> > > - Insert number list of a specific number of various styles by 'M-Enter" with a number prefix.
> > > - Insert directive by 'C-c C-d'.
> > > - Insert directive option by 'C-c C-o'.
> > > - Remove the dependency on a2r.el. Now all the patched codes are from mine.
> >
> > > Hope it's helpful.
> >
> > I'd like to hear the opinion of rst.el's maintainers as well.
> 
> Holy smoke, is this a patch from 2008? Major lag in the reviewers!
> Where is the link?
> Is this the one?
> http://debbugs.gnu.org/cgi-bin/bugreport.cgi?bug=1610
> 
> I had a very quick look at this patch--it looks fine to me (other than
> the overuse of mutable locals/setq).
> 
> About the features: I personally care little about bullet insertion
> functions, I find inserting them manually is good enough, but it
> doesn't hurt to have them there, and others might really like them, so
> I would merge it in. Thanks WeiWei! :-)
> 


It's a very old patch and Stefan Merten has a new version of rst.el.
Here is the link of the new rst.el which already merged part of the
patch. 

http://docutils.sourceforge.net/tools/editors/emacs/rst.el

Stefan's codes are much better than mine, so it better to merge the new
rst.el instead of my old patch. 

I sent a email to you with another two extensions of rst.el days ago,
which are rst-directive.el and rst-links.el. If you think those codes
are fine, they can be merged into the rst.el too. I recommend the
rst-directive.el, which I use in my daily work and saves me lots of
time. 

Hope my terrible coding style isn't taking you too much trouble. 


Best wishes,
Wei-Wei






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

* bug#6531: patch for rst.el updated (patch format revised)
  2012-04-13  6:40     ` Wei-Wei Guo
@ 2012-04-13 12:25       ` Stefan Monnier
  2012-04-14  9:40         ` Stefan Merten
  2012-04-13 15:05       ` Martin Blais
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2012-04-13 12:25 UTC (permalink / raw)
  To: Martin Blais, Stefan Merten, David Goodger; +Cc: Wei-Wei Guo, 6531

> It's a very old patch and Stefan Merten has a new version of rst.el.
> Here is the link of the new rst.el which already merged part of the
> patch. 

> http://docutils.sourceforge.net/tools/editors/emacs/rst.el

Huh?  And why isn't it in Emacs's repository?  If the maintainers don't
push changes back to us (or better yet, use Emacs's repository as the
upstream), then we're better off not having the package in Emacs at all.

Could one of you maintainers merge Emacs's and docutils's versions and
try to avoid such diversion in the future, please?
If you need write access to the repository, just ask for it (which is
done by registering on Savannah and requesting membership in the
"emacs" group).


        Stefan





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

* bug#6531: patch for rst.el updated (patch format revised)
  2012-04-13  6:40     ` Wei-Wei Guo
  2012-04-13 12:25       ` Stefan Monnier
@ 2012-04-13 15:05       ` Martin Blais
  1 sibling, 0 replies; 10+ messages in thread
From: Martin Blais @ 2012-04-13 15:05 UTC (permalink / raw)
  To: Wei-Wei Guo; +Cc: 6531, David Goodger, Stefan Merten

On Fri, Apr 13, 2012, at 14:40, Wei-Wei Guo wrote:
> 在 2012-04-12四的 23:13 -0400,Martin Blais写道:
> > On Thu, Apr 12, 2012, at 16:30, Stefan Monnier wrote:
> > > > The update including:
> > >
> > > > - Insert bullet list by 'M-Enter'.
> > > > - Insert number list "#." by 'M-Enter' with any prefix.
> > > > - Insert number list of a specific number of various styles by 'M-Enter" with a number prefix.
> > > > - Insert directive by 'C-c C-d'.
> > > > - Insert directive option by 'C-c C-o'.
> > > > - Remove the dependency on a2r.el. Now all the patched codes are from mine.
> > >
> > > > Hope it's helpful.
> > >
> > > I'd like to hear the opinion of rst.el's maintainers as well.
> >
> > Holy smoke, is this a patch from 2008? Major lag in the reviewers!
> > Where is the link?
> > Is this the one?
> > http://debbugs.gnu.org/cgi-bin/bugreport.cgi?bug=1610
> >
> > I had a very quick look at this patch--it looks fine to me (other than
> > the overuse of mutable locals/setq).
> >
> > About the features: I personally care little about bullet insertion
> > functions, I find inserting them manually is good enough, but it
> > doesn't hurt to have them there, and others might really like them, so
> > I would merge it in. Thanks WeiWei! :-)
> >
>
>
> It's a very old patch and Stefan Merten has a new version of rst.el.
> Here is the link of the new rst.el which already merged part of the
> patch.
>
> http://docutils.sourceforge.net/tools/editors/emacs/rst.el
>
> Stefan's codes are much better than mine, so it better to merge the new
> rst.el instead of my old patch.
>
> I sent a email to you with another two extensions of rst.el days ago,
> which are rst-directive.el and rst-links.el. If you think those codes
> are fine, they can be merged into the rst.el too. I recommend the
> rst-directive.el, which I use in my daily work and saves me lots of
> time.
>
> Hope my terrible coding style isn't taking you too much trouble.

Nothing personal Weiwei, your coding style is fine. The only important
comments there (and most of Stefan Monnier's suggestions) are about
avoiding using (setq) where unnecessary.

In LISP, the use of setq is considered "poor style" because its syntax
allows a functional form which avoids mutability (Stefan's suggestions
provide good examples of this). Emacs LISP is a bit of a crappy
language because makes mutable operations look like regular functions
(poor naming choices, it's old), but other LISP implementations
emphasize the nastiness of mutability by including a '!' in the name
of all functions which modify their objects. Clojure does this too,
but goes one step further by making its native data structures be all
"persistent" (i.e., you cannot modify them, you can only create "new"
modified versions of them). Haskell and ML go even further and make it
a real PIA to modify anything anywhere, so you end up doing gymnastics
all day long to satisfy the compiler. Some people claim that
mutability is the root of all evil... personally I find it a bit
annoying to have to program in a fully non-mutable world, but I think
that in the particular examples cited above Stefan's proposed changes
make the code clearer.







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

* bug#6531: patch for rst.el updated (patch format revised)
  2012-04-13 12:25       ` Stefan Monnier
@ 2012-04-14  9:40         ` Stefan Merten
  2012-04-16  2:51           ` Stefan Monnier
  2020-09-27 12:49           ` bug#1610: " Lars Ingebrigtsen
  0 siblings, 2 replies; 10+ messages in thread
From: Stefan Merten @ 2012-04-14  9:40 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Wei-Wei Guo, Martin Blais, David Goodger, 6531

[-- Attachment #1: Type: text/plain, Size: 1185 bytes --]

Hi StefanMo!

Yesterday Stefan Monnier wrote:
> Huh?  And why isn't it in Emacs's repository?

This is really a good question.

There also was an intense code review by StefanMo and most suggestions
have been integrated.

> If the maintainers don't
> push changes back to us (or better yet, use Emacs's repository as the
> upstream),

I remember that some time ago I followed a tedious procedure to be
able to do this. I remember the procedure never completed - for
reasons I need to check out.

> then we're better off not having the package in Emacs at all.

This is of course at your option. Simplifying the entering procedure
would certainly help, however.

> Could one of you maintainers merge Emacs's and docutils's versions and
> try to avoid such diversion in the future, please?
> If you need write access to the repository, just ask for it (which is
> done by registering on Savannah and requesting membership in the
> "emacs" group).

I'll check out where the process stuck and get back to you then.

@Martin, Wei-Wei, David: You don't need to care any further about
this. I'll check it out and care for it.


						Grüße

						Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 307 bytes --]

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

* bug#6531: patch for rst.el updated (patch format revised)
  2012-04-14  9:40         ` Stefan Merten
@ 2012-04-16  2:51           ` Stefan Monnier
  2020-09-27 12:49           ` bug#1610: " Lars Ingebrigtsen
  1 sibling, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2012-04-16  2:51 UTC (permalink / raw)
  To: Stefan Merten; +Cc: Wei-Wei Guo, Martin Blais, David Goodger, 6531

>> Huh?  And why isn't it in Emacs's repository?
> This is really a good question.
> There also was an intense code review by StefanMo and most suggestions
> have been integrated.

Good to know.

>> If the maintainers don't push changes back to us (or better yet, use
>> Emacs's repository as the upstream),
> I remember that some time ago I followed a tedious procedure to be
> able to do this.  I remember the procedure never completed - for
> reasons I need to check out.

Hmm...

>> then we're better off not having the package in Emacs at all.
> This is of course at your option.  Simplifying the entering procedure
> would certainly help, however.

Indeed.

> Find below the procedure you asked me to complete. I completed the
> form and sent it back.  After this nothing happened any more.

Oh, this was to clear the copyright issue, so that rst.el could be
installed in Emacs.  That cleared a long time ago and indeed rst.el is
included in Emacs-23.

>> If you need write access to the repository, just ask for it (which is
>> done by registering on Savannah and requesting membership in the
>> "emacs" group).
> May be this is the next step in this whole procedure - I have no idea.

Indeed, unless you prefer to send us patches that we install ourselves.

> I suggest you explain to me what to do next, I do and if the process
> is stuck again I get back to you.

The "next" is to get write access to the repository and for that you
need to do just what you quoted: "registering on Savannah and requesting
membership in the `emacs' group".

After that's done you'll be able to checkout and commit directly.
Of course, in the mean time our rst.el and the docutils one have
diverged (not sure how much), so someone will need to merge them again.

Looks like there's been some miscommunication at some point, I hope this
clears it up finally, and I'm sorry it took so long to figure it out.


        Stefan





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

* bug#1610: bug#6531: patch for rst.el updated (patch format revised)
  2012-04-14  9:40         ` Stefan Merten
  2012-04-16  2:51           ` Stefan Monnier
@ 2020-09-27 12:49           ` Lars Ingebrigtsen
  1 sibling, 0 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-27 12:49 UTC (permalink / raw)
  To: Stefan Merten
  Cc: 6531, Wei-Wei Guo, Stefan Monnier, Martin Blais, 1610,
	David Goodger

Stefan Merten <smerten@oekonux.de> writes:

> There also was an intense code review by StefanMo and most suggestions
> have been integrated.

Looking at rst.el, it looks like all the relevant bits from this very
old bug report were integrated, but the bug report was left open.  So
I'm closing it now.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2020-09-27 12:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-28 13:58 bug#6531: patch for rst.el updated (patch format revised) Wei-Wei Guo
2012-04-12 17:41 ` Lars Magne Ingebrigtsen
2012-04-12 20:30 ` Stefan Monnier
2012-04-13  3:13   ` Martin Blais
2012-04-13  6:40     ` Wei-Wei Guo
2012-04-13 12:25       ` Stefan Monnier
2012-04-14  9:40         ` Stefan Merten
2012-04-16  2:51           ` Stefan Monnier
2020-09-27 12:49           ` bug#1610: " Lars Ingebrigtsen
2012-04-13 15:05       ` Martin Blais

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

	https://git.savannah.gnu.org/cgit/emacs.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).