1
;; Authors: David Goodger <goodger@python.org>;
3
;; Date: $Date: 2003/05/23 13:48:22 $
4
;; Copyright: This module has been placed in the public domain.
6
;; Support code for editing reStructuredText with Emacs indented-text mode.
7
;; The goal is to create an integrated reStructuredText editing mode.
12
;; 2003-02-25 (blais): updated repeat-last-character function and added
13
;; a few routines for navigating between titles.
15
(defun replace-lines (fromchar tochar)
17
"Replace flush-left lines, consisting of multiple FROMCHAR characters,
18
with equal-length lines of TOCHAR."
20
cSearch for flush-left lines of char:
21
cand replace with char: ")
23
(let* ((fromstr (string fromchar))
24
(searchre (concat "^" (regexp-quote fromstr) "+ *$"))
28
(search-forward-regexp searchre)
29
(setq found (1+ found))
30
(search-backward fromstr) ;; point will be *before* last char
33
(setq l (- p (point)))
35
(insert-char tochar l))
37
(message (format "%d lines replaced." found)))))))
39
(defun repeat-last-character ()
41
"Fills the current line up to the length of the preceding line (if not empty),
42
using the last character on the current line. If the preceding line is empty,
43
or if a prefix argument is provided, fill up to the fill-column.
45
If the current line is longer than the desired length, shave the characters off
46
the current line to fit the desired length.
48
As an added convenience, if the command is repeated immediately, the alternative
49
behaviour is performed."
53
;; It would be useful if only these characters were repeated:
54
;; =-`:.'"~^_*+#<>!$%&(),/;?@[\]{|}
55
;; Especially, empty lines shouldn't be repeated.
58
(let* ((curcol (current-column))
59
(curline (+ (count-lines (point-min) (point)) (if (eq curcol 0) 1 0)))
60
(lbp (line-beginning-position 0))
61
(prevcol (if (= curline 1)
66
(skip-chars-backward " \t" lbp)
67
(let ((cc (current-column)))
68
(if (= cc 0) fill-column cc)))))
70
(cond (current-prefix-arg fill-column)
71
((equal last-command 'repeat-last-character)
72
(if (= curcol fill-column) prevcol fill-column))
74
(if (= prevcol 0) fill-column prevcol))) )) )
76
(if (> (current-column) rightmost-column)
77
;; shave characters off the end
78
(delete-region (- (point)
79
(- (current-column) rightmost-column))
81
;; fill with last characters
82
(insert-char (preceding-char)
83
(- rightmost-column (current-column)))) ))
85
(defun reST-title-char-p (c)
87
"Returns true if the given character is a valid title char."
88
(and (string-match "[-=`:\\.'\"~^_*+#<>!$%&(),/;?@\\\|]"
89
(char-to-string c)) t))
91
(defun reST-forward-title ()
93
"Skip to the next restructured text section title."
97
(forward-char) ;; in case we're right on a title
100
(and (re-search-forward "^[A-Za-z0-9].*[ \t]*$" nil t)
101
(reST-title-char-p (char-after (+ (point) 1)))
102
(looking-at (format "\n%c\\{%d,\\}[ \t]*$"
103
(char-after (+ (point) 1))
104
(current-column))))))
107
(if newpoint (goto-char newpoint)) ))
109
(defun reST-backward-title ()
111
"Skip to the previous restructured text section title."
115
;;(forward-char) ;; in case we're right on a title
118
(and (or (backward-char) t)
119
(re-search-backward "^[A-Za-z0-9].*[ \t]*$" nil t)
121
(reST-title-char-p (char-after (+ (point) 1)))
122
(looking-at (format "\n%c\\{%d,\\}[ \t]*$"
123
(char-after (+ (point) 1))
124
(current-column))))))
127
(if newpoint (goto-char newpoint)) ))
129
(defun join-paragraph ()
131
"Join lines in current paragraph into one line, removing end-of-lines."
134
(backward-paragraph 1)
136
(let ((start (point))) ; remember where we are
137
(forward-paragraph 1) ; go to the end of the paragraph
138
(beginning-of-line 0) ; go to the beginning of the previous line
139
(while (< start (point)) ; as long as we haven't passed where we started
140
(delete-indentation) ; join this line to the line before
141
(beginning-of-line))))) ; and go back to the beginning of the line
143
(defun force-fill-paragraph ()
145
"Fill paragraph at point, first joining the paragraph's lines into one.
146
This is useful for filling list item paragraphs."
149
(fill-paragraph nil))