aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2010-11-17 22:02:15 -0500
committerStefan Monnier2010-11-17 22:02:15 -0500
commit8bbb7dd8a6d08540a81a7a2baa2274d8e6d65c92 (patch)
tree0cda6e998d72131a06c42952b9cb80073510861d
parentb7e270a2c46ee2d7df7f97fff5a16089ea55622b (diff)
downloademacs-8bbb7dd8a6d08540a81a7a2baa2274d8e6d65c92.tar.gz
emacs-8bbb7dd8a6d08540a81a7a2baa2274d8e6d65c92.zip
* lisp/textmodes/rst.el: Minor cleanup to improve style.
(rst-get-decoration): Eliminate unneeded assignment. (rst-update-section, rst-promote-region, rst-straighten-decorations) (rst-section-tree, rst-adjust): Use point-marker. (rst-toc-mode-mouse-goto): Avoid setq. (rst-shift-region-guts, rst-shift-region-left) (rst-iterate-leftmost-paragraphs, rst-iterate-leftmost-paragraphs-2) (rst-convert-bullets-to-enumeration): Use copy-marker.
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/textmodes/rst.el102
2 files changed, 53 insertions, 59 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 48eb3c9e955..dc5761109d7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,15 @@
12010-11-18 Stefan Monnier <monnier@iro.umontreal.ca> 12010-11-18 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 Minor cleanup to improve style.
4 * textmodes/rst.el (rst-update-section): Use point-marker.
5 (rst-get-decoration): Eliminate unneeded assignment.
6 (rst-promote-region, rst-straighten-decorations)
7 (rst-section-tree, rst-adjust): Use point-marker.
8 (rst-toc-mode-mouse-goto): Avoid setq.
9 (rst-shift-region-guts, rst-shift-region-left)
10 (rst-iterate-leftmost-paragraphs, rst-iterate-leftmost-paragraphs-2)
11 (rst-convert-bullets-to-enumeration): Use copy-marker.
12
3 * minibuffer.el (completion-fail-discreetly): New var. 13 * minibuffer.el (completion-fail-discreetly): New var.
4 (completion--do-completion): Use it. 14 (completion--do-completion): Use it.
5 15
diff --git a/lisp/textmodes/rst.el b/lisp/textmodes/rst.el
index afc4dd892c9..5bf1a7c7894 100644
--- a/lisp/textmodes/rst.el
+++ b/lisp/textmodes/rst.el
@@ -698,11 +698,9 @@ existing decoration, they are removed before adding the
698requested decoration." 698requested decoration."
699 699
700 (interactive) 700 (interactive)
701 (let (marker
702 len)
703
704 (end-of-line) 701 (end-of-line)
705 (setq marker (point-marker)) 702 (let ((marker (point-marker))
703 len)
706 704
707 ;; Fixup whitespace at the beginning and end of the line 705 ;; Fixup whitespace at the beginning and end of the line
708 (if (or (null indent) (eq style 'simple)) 706 (if (or (null indent) (eq style 'simple))
@@ -789,7 +787,7 @@ This function does not detect the hierarchy of decorations, it
789just finds all of them in a file. You can then invoke another 787just finds all of them in a file. You can then invoke another
790function to remove redundancies and inconsistencies." 788function to remove redundancies and inconsistencies."
791 789
792 (let (positions 790 (let ((positions ())
793 (curline 1)) 791 (curline 1))
794 ;; Iterate over all the section titles/decorations in the file. 792 ;; Iterate over all the section titles/decorations in the file.
795 (save-excursion 793 (save-excursion
@@ -870,7 +868,7 @@ A decoration can be said to exist if the style is not nil.
870A point can be specified to go to the given location before 868A point can be specified to go to the given location before
871extracting the decoration." 869extracting the decoration."
872 870
873 (let (char style indent) 871 (let (char style)
874 (save-excursion 872 (save-excursion
875 (if point (goto-char point)) 873 (if point (goto-char point))
876 (beginning-of-line) 874 (beginning-of-line)
@@ -879,10 +877,10 @@ extracting the decoration."
879 (forward-line -1) 877 (forward-line -1)
880 (rst-line-homogeneous-nodent-p))) 878 (rst-line-homogeneous-nodent-p)))
881 879
882 (under (save-excursion 880 (under (save-excursion
883 (forward-line +1) 881 (forward-line +1)
884 (rst-line-homogeneous-nodent-p))) 882 (rst-line-homogeneous-nodent-p)))
885 ) 883 )
886 884
887 ;; Check that the line above the overline is not part of a title 885 ;; Check that the line above the overline is not part of a title
888 ;; above it. 886 ;; above it.
@@ -910,15 +908,11 @@ extracting the decoration."
910 ;; Both overline and underline. 908 ;; Both overline and underline.
911 (t 909 (t
912 (setq char under 910 (setq char under
913 style 'over-and-under)) 911 style 'over-and-under)))))
914 ) 912 ;; Return values.
915 ) 913 (list char style
916 ) 914 ;; Find indentation.
917 ;; Find indentation. 915 (save-excursion (back-to-indentation) (current-column))))))
918 (setq indent (save-excursion (back-to-indentation) (current-column)))
919 )
920 ;; Return values.
921 (list char style indent)))
922 916
923 917
924(defun rst-get-decorations-around (&optional alldecos) 918(defun rst-get-decorations-around (&optional alldecos)
@@ -1041,7 +1035,7 @@ b. a negative numerical argument, which generally inverts the
1041 (interactive) 1035 (interactive)
1042 1036
1043 (let* (;; Save our original position on the current line. 1037 (let* (;; Save our original position on the current line.
1044 (origpt (set-marker (make-marker) (point))) 1038 (origpt (point-marker))
1045 1039
1046 ;; Parse the positive and negative prefix arguments. 1040 ;; Parse the positive and negative prefix arguments.
1047 (reverse-direction 1041 (reverse-direction
@@ -1395,32 +1389,28 @@ hierarchy is similar to that used by `rst-adjust-decoration'."
1395 ;; Create a list of markers for all the decorations which are found within 1389 ;; Create a list of markers for all the decorations which are found within
1396 ;; the region. 1390 ;; the region.
1397 (save-excursion 1391 (save-excursion
1398 (let (m line) 1392 (let (line)
1399 (while (and cur (< (setq line (caar cur)) region-end-line)) 1393 (while (and cur (< (setq line (caar cur)) region-end-line))
1400 (setq m (make-marker))
1401 (goto-char (point-min)) 1394 (goto-char (point-min))
1402 (forward-line (1- line)) 1395 (forward-line (1- line))
1403 (push (list (set-marker m (point)) (cdar cur)) marker-list) 1396 (push (list (point-marker) (cdar cur)) marker-list)
1404 (setq cur (cdr cur)) )) 1397 (setq cur (cdr cur)) ))
1405 1398
1406 ;; Apply modifications. 1399 ;; Apply modifications.
1407 (let (nextdeco) 1400 (dolist (p marker-list)
1408 (dolist (p marker-list) 1401 ;; Go to the decoration to promote.
1409 ;; Go to the decoration to promote. 1402 (goto-char (car p))
1410 (goto-char (car p)) 1403
1411 1404 ;; Update the decoration.
1412 ;; Rotate the next decoration. 1405 (apply 'rst-update-section
1413 (setq nextdeco (rst-get-next-decoration 1406 ;; Rotate the next decoration.
1414 (cadr p) hier suggestion demote)) 1407 (rst-get-next-decoration
1415 1408 (cadr p) hier suggestion demote))
1416 ;; Update the decoration. 1409
1417 (apply 'rst-update-section nextdeco) 1410 ;; Clear marker to avoid slowing down the editing after we're done.
1418 1411 (set-marker (car p) nil))
1419 ;; Clear marker to avoid slowing down the editing after we're done.
1420 (set-marker (car p) nil)
1421 ))
1422 (setq deactivate-mark nil) 1412 (setq deactivate-mark nil)
1423 ))) 1413 )))
1424 1414
1425 1415
1426 1416
@@ -1463,11 +1453,10 @@ in order to adapt it to our preferred style."
1463 (levels-and-markers (mapcar 1453 (levels-and-markers (mapcar
1464 (lambda (deco) 1454 (lambda (deco)
1465 (cons (rst-position (cdr deco) hier) 1455 (cons (rst-position (cdr deco) hier)
1466 (let ((m (make-marker))) 1456 (progn
1467 (goto-char (point-min)) 1457 (goto-char (point-min))
1468 (forward-line (1- (car deco))) 1458 (forward-line (1- (car deco)))
1469 (set-marker m (point)) 1459 (point-marker))))
1470 m)))
1471 alldecos)) 1460 alldecos))
1472 ) 1461 )
1473 (dolist (lm levels-and-markers) 1462 (dolist (lm levels-and-markers)
@@ -1511,7 +1500,7 @@ section levels."
1511 "Find all the positions of prefixes in region between BEG and END. 1500 "Find all the positions of prefixes in region between BEG and END.
1512This is used to find bullets and enumerated list items. PFX-RE 1501This is used to find bullets and enumerated list items. PFX-RE
1513is a regular expression for matching the lines with items." 1502is a regular expression for matching the lines with items."
1514 (let (pfx) 1503 (let ((pfx ()))
1515 (save-excursion 1504 (save-excursion
1516 (goto-char beg) 1505 (goto-char beg)
1517 (while (< (point) end) 1506 (while (< (point) end)
@@ -1635,10 +1624,9 @@ child. This has advantages later in processing the graph."
1635 (forward-line (1- (car deco))) 1624 (forward-line (1- (car deco)))
1636 (list (gethash (cons (cadr deco) (caddr deco)) levels) 1625 (list (gethash (cons (cadr deco) (caddr deco)) levels)
1637 (rst-get-stripped-line) 1626 (rst-get-stripped-line)
1638 (let ((m (make-marker))) 1627 (progn
1639 (beginning-of-line 1) 1628 (beginning-of-line 1)
1640 (set-marker m (point))) 1629 (point-marker))))
1641 ))
1642 alldecos))) 1630 alldecos)))
1643 1631
1644 (let ((lcontnr (cons nil lines))) 1632 (let ((lcontnr (cons nil lines)))
@@ -2057,11 +2045,11 @@ brings the cursor in that section."
2057 "In `rst-toc' mode, go to the occurrence whose line you click on. 2045 "In `rst-toc' mode, go to the occurrence whose line you click on.
2058EVENT is the input event." 2046EVENT is the input event."
2059 (interactive "e") 2047 (interactive "e")
2060 (let (pos) 2048 (let ((pos
2061 (with-current-buffer (window-buffer (posn-window (event-end event))) 2049 (with-current-buffer (window-buffer (posn-window (event-end event)))
2062 (save-excursion 2050 (save-excursion
2063 (goto-char (posn-point (event-end event))) 2051 (goto-char (posn-point (event-end event)))
2064 (setq pos (rst-toc-mode-find-section)))) 2052 (rst-toc-mode-find-section)))))
2065 (pop-to-buffer (marker-buffer pos)) 2053 (pop-to-buffer (marker-buffer pos))
2066 (goto-char pos) 2054 (goto-char pos)
2067 (recenter 5))) 2055 (recenter 5)))
@@ -2306,8 +2294,8 @@ of (COLUMN-NUMBER . LINE) pairs."
2306 2294
2307(defun rst-shift-region-guts (find-next-fun offset-fun) 2295(defun rst-shift-region-guts (find-next-fun offset-fun)
2308 "(See `rst-shift-region-right' for a description)." 2296 "(See `rst-shift-region-right' for a description)."
2309 (let* ((mbeg (set-marker (make-marker) (region-beginning))) 2297 (let* ((mbeg (copy-marker (region-beginning)))
2310 (mend (set-marker (make-marker) (region-end))) 2298 (mend (copy-marker (region-end)))
2311 (tabs (rst-compute-bullet-tabs mbeg)) 2299 (tabs (rst-compute-bullet-tabs mbeg))
2312 (leftmostcol (rst-find-leftmost-column (region-beginning) (region-end))) 2300 (leftmostcol (rst-find-leftmost-column (region-beginning) (region-end)))
2313 ) 2301 )
@@ -2386,8 +2374,8 @@ Also, if invoked with a negative prefix arg, the entire
2386indentation is removed, up to the leftmost character in the 2374indentation is removed, up to the leftmost character in the
2387region, and automatic filling is disabled." 2375region, and automatic filling is disabled."
2388 (interactive "P") 2376 (interactive "P")
2389 (let ((mbeg (set-marker (make-marker) (region-beginning))) 2377 (let ((mbeg (copy-marker (region-beginning)))
2390 (mend (set-marker (make-marker) (region-end))) 2378 (mend (copy-marker (region-end)))
2391 (leftmostcol (rst-find-leftmost-column 2379 (leftmostcol (rst-find-leftmost-column
2392 (region-beginning) (region-end))) 2380 (region-beginning) (region-end)))
2393 (rst-shift-fill-region 2381 (rst-shift-fill-region
@@ -2421,8 +2409,7 @@ Set FIRST-ONLY to true if you want to callback on the first line
2421of each paragraph only." 2409of each paragraph only."
2422 `(save-excursion 2410 `(save-excursion
2423 (let ((leftcol (rst-find-leftmost-column ,beg ,end)) 2411 (let ((leftcol (rst-find-leftmost-column ,beg ,end))
2424 (endm (set-marker (make-marker) ,end)) 2412 (endm (copy-marker ,end)))
2425 )
2426 2413
2427 (do* (;; Iterate lines 2414 (do* (;; Iterate lines
2428 (l (progn (goto-char ,beg) (back-to-indentation)) 2415 (l (progn (goto-char ,beg) (back-to-indentation))
@@ -2460,8 +2447,7 @@ first of a paragraph."
2460 2447
2461 `(save-excursion 2448 `(save-excursion
2462 (let ((,leftmost (rst-find-leftmost-column ,beg ,end)) 2449 (let ((,leftmost (rst-find-leftmost-column ,beg ,end))
2463 (endm (set-marker (make-marker) ,end)) 2450 (endm (copy-marker ,end)))
2464 )
2465 2451
2466 (do* (;; Iterate lines 2452 (do* (;; Iterate lines
2467 (l (progn (goto-char ,beg) (back-to-indentation)) 2453 (l (progn (goto-char ,beg) (back-to-indentation))
@@ -2538,9 +2524,7 @@ region to enumerated lists, renumbering as necessary."
2538 (let* (;; Find items and convert the positions to markers. 2524 (let* (;; Find items and convert the positions to markers.
2539 (items (mapcar 2525 (items (mapcar
2540 (lambda (x) 2526 (lambda (x)
2541 (cons (let ((m (make-marker))) 2527 (cons (copy-marker (car x))
2542 (set-marker m (car x))
2543 m)
2544 (cdr x))) 2528 (cdr x)))
2545 (rst-find-pfx-in-region beg end rst-re-items))) 2529 (rst-find-pfx-in-region beg end rst-re-items)))
2546 (count 1) 2530 (count 1)