;;; rst.el --- Mode for viewing and editing reStructuredText-documents.
-;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-;; Free Software Foundation, Inc.
+;; Copyright (C) 2003-2011 Free Software Foundation, Inc.
;; Authors: Martin Blais <blais@furius.ca>,
;; Stefan Merten <smerten@oekonux.de>,
(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.
+ ;; Homogenize 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)
;;;###autoload
(define-minor-mode rst-minor-mode
- "ReST Minor Mode.
-Toggle ReST minor mode.
-With no argument, this command toggles the mode.
-Non-null prefix argument turns on the mode.
-Null prefix argument turns off the mode.
+ "Toggle ReST minor mode.
+With a prefix argument ARG, enable ReST minor mode if ARG is
+positive, and disable it otherwise. If called from Lisp, enable
+the mode if ARG is omitted or nil.
When ReST minor mode is enabled, the ReST mode keybindings
are installed on top of the major mode bindings. Use this
\f
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Section Decoration Adjusment
-;; ============================
+;; Section Decoration Adjustment
+;; =============================
;;
;; The following functions implement a smart automatic title sectioning feature.
;; The idea is that with the cursor sitting on a section title, we try to get as
requested decoration."
(interactive)
- (let (marker
- len)
-
(end-of-line)
- (setq marker (point-marker))
+ (let ((marker (point-marker))
+ len)
;; Fixup whitespace at the beginning and end of the line
(if (or (null indent) (eq style 'simple))
just finds all of them in a file. You can then invoke another
function to remove redundancies and inconsistencies."
- (let (positions
+ (let ((positions ())
(curline 1))
;; Iterate over all the section titles/decorations in the file.
(save-excursion
A point can be specified to go to the given location before
extracting the decoration."
- (let (char style indent)
+ (let (char style)
(save-excursion
(if point (goto-char point))
(beginning-of-line)
(forward-line -1)
(rst-line-homogeneous-nodent-p)))
- (under (save-excursion
- (forward-line +1)
- (rst-line-homogeneous-nodent-p)))
- )
+ (under (save-excursion
+ (forward-line +1)
+ (rst-line-homogeneous-nodent-p)))
+ )
;; Check that the line above the overline is not part of a title
;; above it.
;; Both overline and underline.
(t
(setq char under
- style 'over-and-under))
- )
- )
- )
- ;; Find indentation.
- (setq indent (save-excursion (back-to-indentation) (current-column)))
- )
- ;; Return values.
- (list char style indent)))
+ style 'over-and-under)))))
+ ;; Return values.
+ (list char style
+ ;; Find indentation.
+ (save-excursion (back-to-indentation) (current-column))))))
(defun rst-get-decorations-around (&optional alldecos)
(interactive)
(let* (;; Save our original position on the current line.
- (origpt (set-marker (make-marker) (point)))
+ (origpt (point-marker))
;; Parse the positive and negative prefix arguments.
(reverse-direction
;; Create a list of markers for all the decorations which are found within
;; the region.
(save-excursion
- (let (m line)
+ (let (line)
(while (and cur (< (setq line (caar cur)) region-end-line))
- (setq m (make-marker))
(goto-char (point-min))
(forward-line (1- line))
- (push (list (set-marker m (point)) (cdar cur)) marker-list)
+ (push (list (point-marker) (cdar cur)) marker-list)
(setq cur (cdr cur)) ))
;; Apply modifications.
- (let (nextdeco)
- (dolist (p marker-list)
- ;; Go to the decoration to promote.
- (goto-char (car p))
-
- ;; Rotate the next decoration.
- (setq nextdeco (rst-get-next-decoration
- (cadr p) hier suggestion demote))
-
- ;; Update the decoration.
- (apply 'rst-update-section nextdeco)
-
- ;; Clear marker to avoid slowing down the editing after we're done.
- (set-marker (car p) nil)
- ))
+ (dolist (p marker-list)
+ ;; Go to the decoration to promote.
+ (goto-char (car p))
+
+ ;; Update the decoration.
+ (apply 'rst-update-section
+ ;; Rotate the next decoration.
+ (rst-get-next-decoration
+ (cadr p) hier suggestion demote))
+
+ ;; Clear marker to avoid slowing down the editing after we're done.
+ (set-marker (car p) nil))
(setq deactivate-mark nil)
- )))
+ )))
(levels-and-markers (mapcar
(lambda (deco)
(cons (rst-position (cdr deco) hier)
- (let ((m (make-marker)))
+ (progn
(goto-char (point-min))
(forward-line (1- (car deco)))
- (set-marker m (point))
- m)))
+ (point-marker))))
alldecos))
)
(dolist (lm levels-and-markers)
"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 lines with items."
- (let (pfx)
+ (let ((pfx ()))
(save-excursion
(goto-char beg)
(while (< (point) end)
(defvar rst-preferred-bullets
'(?- ?* ?+)
- "List of favourite bullets to set for straightening bullets.")
+ "List of favorite bullets to set for straightening bullets.")
(defun rst-straighten-bullets-region (beg end)
"Make all the bulleted list items in the region consistent.
(forward-line (1- (car deco)))
(list (gethash (cons (cadr deco) (caddr deco)) levels)
(rst-get-stripped-line)
- (let ((m (make-marker)))
+ (progn
(beginning-of-line 1)
- (set-marker m (point)))
- ))
+ (point-marker))))
alldecos)))
(let ((lcontnr (cons nil lines)))
"In `rst-toc' mode, go to the occurrence whose line you click on.
EVENT is the input event."
(interactive "e")
- (let (pos)
+ (let ((pos
(with-current-buffer (window-buffer (posn-window (event-end event)))
(save-excursion
(goto-char (posn-point (event-end event)))
- (setq pos (rst-toc-mode-find-section))))
+ (rst-toc-mode-find-section)))))
(pop-to-buffer (marker-buffer pos))
(goto-char pos)
(recenter 5)))
(defun rst-shift-region-guts (find-next-fun offset-fun)
"(See `rst-shift-region-right' for a description)."
- (let* ((mbeg (set-marker (make-marker) (region-beginning)))
- (mend (set-marker (make-marker) (region-end)))
+ (let* ((mbeg (copy-marker (region-beginning)))
+ (mend (copy-marker (region-end)))
(tabs (rst-compute-bullet-tabs mbeg))
(leftmostcol (rst-find-leftmost-column (region-beginning) (region-end)))
)
(indent-rigidly
mbeg mend
- ;; Find the next tab after the leftmost columnt.
+ ;; Find the next tab after the leftmost column.
(let ((tab (funcall find-next-fun tabs leftmostcol)))
(if tab
indentation is removed, up to the leftmost character in the
region, and automatic filling is disabled."
(interactive "P")
- (let ((mbeg (set-marker (make-marker) (region-beginning)))
- (mend (set-marker (make-marker) (region-end)))
+ (let ((mbeg (copy-marker (region-beginning)))
+ (mend (copy-marker (region-end)))
(leftmostcol (rst-find-leftmost-column
(region-beginning) (region-end)))
(rst-shift-fill-region
of each paragraph only."
`(save-excursion
(let ((leftcol (rst-find-leftmost-column ,beg ,end))
- (endm (set-marker (make-marker) ,end))
- )
+ (endm (copy-marker ,end)))
(do* (;; Iterate lines
(l (progn (goto-char ,beg) (back-to-indentation))
`(save-excursion
(let ((,leftmost (rst-find-leftmost-column ,beg ,end))
- (endm (set-marker (make-marker) ,end))
- )
+ (endm (copy-marker ,end)))
(do* (;; Iterate lines
(l (progn (goto-char ,beg) (back-to-indentation))
;;------------------------------------------------------------------------------
;; FIXME: these next functions should become part of a larger effort to redo the
-;; bullets in bulletted lists. The enumerate would just be one of the possible
+;; bullets in bulleted lists. The enumerate would just be one of the possible
;; outputs.
;;
;; FIXME: TODO we need to do the enumeration removal as well.
(let* (;; Find items and convert the positions to markers.
(items (mapcar
(lambda (x)
- (cons (let ((m (make-marker)))
- (set-marker m (car x))
- m)
+ (cons (copy-marker (car x))
(cdr x)))
(rst-find-pfx-in-region beg end rst-re-items)))
(count 1)
(rst-define-level-faces)))
;; Faces for displaying items on several levels; these definitions define
-;; different shades of grey where the lightest one (i.e. least contrasting) is
+;; different shades of gray where the lightest one (i.e. least contrasting) is
;; used for level 1
(defcustom rst-level-face-max 6
"Maximum depth of levels for which section title faces are defined."
rst-level-face-base-color
(+ (* (1- i) rst-level-face-step-light)
rst-level-face-base-light))))
- (make-empty-face sym)
- (set-face-doc-string sym doc)
- (set-face-background sym col)
- (set sym sym)
- (setq i (1+ i))))))
+ (unless (facep sym)
+ (make-empty-face sym)
+ (set-face-doc-string sym doc)
+ (set-face-background sym col)
+ (set sym sym))
+ (setq i (1+ i))))))
(rst-define-level-faces)
;; There seems to be a bug leading to error "Stack overflow in regexp
;; matcher" when "|" or "\\*" are the characters searched for
- (re-imendbeg
- (if (< emacs-major-version 21)
- "]"
- "\\]\\|\\\\."))
+ (re-imendbeg "\\]\\|\\\\.")
;; inline markup content end
(re-imend (concat re-imendbeg "\\)*[^\t \\\\]\\)"))
;; inline markup content without asterisk
:group 'rst
:version "21.1")
-(defvar rst-compile-toolsets
- '((html . ("rst2html.py" ".html" nil))
- (latex . ("rst2latex.py" ".tex" nil))
- (newlatex . ("rst2newlatex.py" ".tex" nil))
- (pseudoxml . ("rst2pseudoxml.py" ".xml" nil))
- (xml . ("rst2xml.py" ".xml" nil)))
+(defcustom rst-compile-toolsets
+ `((html ,(if (executable-find "rst2html.py") "rst2html.py" "rst2html")
+ ".html" nil)
+ (latex ,(if (executable-find "rst2latex.py") "rst2latex.py" "rst2latex")
+ ".tex" nil)
+ (newlatex ,(if (executable-find "rst2newlatex.py") "rst2newlatex.py"
+ "rst2newlatex")
+ ".tex" nil)
+ (pseudoxml ,(if (executable-find "rst2pseudoxml.py") "rst2pseudoxml.py"
+ "rst2pseudoxml")
+ ".xml" nil)
+ (xml ,(if (executable-find "rst2xml.py") "rst2xml.py" "rst2xml")
+ ".xml" nil)
+ (pdf ,(if (executable-find "rst2pdf.py") "rst2pdf.py" "rst2pdf")
+ ".pdf" nil)
+ (s5 ,(if (executable-find "rst2s5.py") "rst2s5.py" "rst2s5")
+ ".html" nil))
"Table describing the command to use for each toolset.
An association list of the toolset to a list of the (command to use,
extension of produced filename, options to the tool (nil or a
-string)) to be used for converting the document.")
+string)) to be used for converting the document."
+ :type '(alist :options (html latex newlatex pseudoxml xml pdf s5)
+ :key-type symbol
+ :value-type (list :tag "Specification"
+ (file :tag "Command")
+ (string :tag "File extension")
+ (choice :tag "Command options"
+ (const :tag "No options" nil)
+ (string :tag "Options"))))
+ :group 'rst
+ :version "24.1")
;; Note for Python programmers not familiar with association lists: you can set
;; values in an alists like this, e.g. :
(shell-command-on-region
(if mark-active (region-beginning) (point-min))
(if mark-active (region-end) (point-max))
- "rst2pseudoxml.py"
+ (cadr (assq 'pseudoxml rst-compile-toolsets))
standard-output)))
(defvar rst-pdf-program "xpdf"
(defun rst-compile-pdf-preview ()
"Convert the document to a PDF file and launch a preview program."
(interactive)
- (let* ((tmp-filename "/tmp/out.pdf")
- (command (format "rst2pdf.py %s %s && %s %s"
+ (let* ((tmp-filename (make-temp-file "rst-out" nil ".pdf"))
+ (command (format "%s %s %s && %s %s"
+ (cadr (assq 'pdf rst-compile-toolsets))
buffer-file-name tmp-filename
rst-pdf-program tmp-filename)))
(start-process-shell-command "rst-pdf-preview" nil command)
(defun rst-compile-slides-preview ()
"Convert the document to an S5 slide presentation and launch a preview program."
(interactive)
- (let* ((tmp-filename "/tmp/slides.html")
- (command (format "rst2s5.py %s %s && %s %s"
+ (let* ((tmp-filename (make-temp-file "rst-slides" nil ".html"))
+ (command (format "%s %s %s && %s %s"
+ (cadr (assq 's5 rst-compile-toolsets))
buffer-file-name tmp-filename
rst-slides-program tmp-filename)))
(start-process-shell-command "rst-slides-preview" nil command)
"A portable function that returns non-nil if the mark is active."
(cond
((fboundp 'region-active-p) (region-active-p))
- ((boundp 'transient-mark-mode) transient-mark-mode mark-active)))
-
+ ((boundp 'transient-mark-mode) (and transient-mark-mode mark-active))
+ (t mark-active)))
\f
(provide 'rst)
-;; arch-tag: 255ac0a3-a689-44cb-8643-04ca55ae490d
;;; rst.el ends here