[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/idlwave 985427dd6a 274/360: Calculate beginning/end of
From: |
ELPA Syncer |
Subject: |
[elpa] externals/idlwave 985427dd6a 274/360: Calculate beginning/end of commented paragraphs. |
Date: |
Sun, 28 Apr 2024 00:59:32 -0400 (EDT) |
branch: externals/idlwave
commit 985427dd6ae1c8b71f1ff080411fb8aed8c94718
Author: JD Smith <jdtsmith@gmail.com>
Commit: JD Smith <jdtsmith@gmail.com>
Calculate beginning/end of commented paragraphs.
Used for filling and auto-filling commented paragraphs.
Auto-filled paragraphs were not using the correct line to calculate
hanging indent. The `idlwave-commented-paragraph-beg-end' function
now finds the correct commented paragraph boundaries.
---
idlwave.el | 113 +++++++++++++++++++++++++++++++++----------------------------
1 file changed, 62 insertions(+), 51 deletions(-)
diff --git a/idlwave.el b/idlwave.el
index c99c2c84f7..aecacbda71 100644
--- a/idlwave.el
+++ b/idlwave.el
@@ -3286,6 +3286,60 @@ If successful, leaves point after the match, otherwise,
does not move point."
(if (not found) (goto-char here))
found))
+(defun idlwave-commented-paragraph-beg-end ()
+ "Find and return the beginning and end position of a commented paragraph.
+End is calculated as distance from end of buffer, to accommodate
+additions from filling."
+ (let (pre diff fill-prefix-reg bcl start end)
+ (beginning-of-line)
+ (setq bcl (point))
+ (re-search-forward
+ (concat "^[ \t]*" comment-start "+")
+ (save-excursion (end-of-line) (point))
+ t)
+ ;; Get the comment leader on the line and its length
+ (setq pre (current-column))
+ ;; the comment leader is the indentation plus exactly the
+ ;; number of consecutive ";".
+ (setq fill-prefix-reg
+ (concat
+ (setq fill-prefix
+ (regexp-quote
+ (buffer-substring (save-excursion
+ (beginning-of-line) (point))
+ (point))))
+ "[^;]"))
+
+ ;; Mark the beginning and end of the paragraph
+ (goto-char bcl)
+ (while (and (looking-at fill-prefix-reg)
+ (not (looking-at paragraph-separate))
+ (not (bobp)))
+ (forward-line -1))
+ ;; Move to first line of paragraph
+ (if (and (/= (point) bcl) (not (bobp)))
+ (forward-line 1))
+ (setq start (point))
+ (goto-char bcl)
+ (while (and (looking-at fill-prefix-reg)
+ (not (looking-at paragraph-separate))
+ (not (eobp)))
+ (forward-line 1))
+ (beginning-of-line)
+ (if (or (not (looking-at fill-prefix-reg))
+ (looking-at paragraph-separate))
+ (forward-line -1))
+ (end-of-line)
+ ;; if at end of buffer add a newline (need this because
+ ;; fill-region needs END to be at the beginning of line after
+ ;; the paragraph or it will add a line).
+ (if (eobp)
+ (progn (insert ?\n) (backward-char 1)))
+ ;; Set END to the beginning of line after the paragraph
+ ;; N.B. END is calculated as distance from end of buffer
+ (setq end (- (point-max) (point) 1))
+ (list start end pre)))
+
(defun idlwave-fill-paragraph (&optional nohang)
"Fill paragraphs in comments.
A paragraph is made up of all contiguous lines having the same comment
@@ -3307,8 +3361,7 @@ ignored."
(looking-at comment-start))
(let
((indent 999)
- pre here diff fill-prefix-reg bcl first-indent
- hang start end)
+ first-indent hang here pre start end)
;; Change tabs to spaces in the surrounding paragraph.
;; The surrounding paragraph will be the largest containing block of
;; contiguous line comments. Thus, we may be changing tabs in
@@ -3325,54 +3378,11 @@ ignored."
(setq end (point)))
(untabify start end)
;;
- (setq here (point))
- (beginning-of-line)
- (setq bcl (point))
- (re-search-forward
- (concat "^[ \t]*" comment-start "+")
- (save-excursion (end-of-line) (point))
- t)
- ;; Get the comment leader on the line and its length
- (setq pre (current-column))
- ;; the comment leader is the indentation plus exactly the
- ;; number of consecutive ";".
- (setq fill-prefix-reg
- (concat
- (setq fill-prefix
- (regexp-quote
- (buffer-substring (save-excursion
- (beginning-of-line) (point))
- (point))))
- "[^;]"))
-
- ;; Mark the beginning and end of the paragraph
- (goto-char bcl)
- (while (and (looking-at fill-prefix-reg)
- (not (looking-at paragraph-separate))
- (not (bobp)))
- (forward-line -1))
- ;; Move to first line of paragraph
- (if (/= (point) bcl)
- (forward-line 1))
- (setq start (point))
- (goto-char bcl)
- (while (and (looking-at fill-prefix-reg)
- (not (looking-at paragraph-separate))
- (not (eobp)))
- (forward-line 1))
- (beginning-of-line)
- (if (or (not (looking-at fill-prefix-reg))
- (looking-at paragraph-separate))
- (forward-line -1))
- (end-of-line)
- ;; if at end of buffer add a newline (need this because
- ;; fill-region needs END to be at the beginning of line after
- ;; the paragraph or it will add a line).
- (if (eobp)
- (progn (insert ?\n) (backward-char 1)))
- ;; Set END to the beginning of line after the paragraph
- ;; END is calculated as distance from end of buffer
- (setq end (- (point-max) (point) 1))
+ (setq here (point)
+ start (idlwave-commented-paragraph-beg-end)
+ end (cadr start)
+ pre (car (cddr start))
+ start (car start))
;;
;; Calculate the indentation for the paragraph.
;;
@@ -3527,7 +3537,8 @@ non-nil."
(let ((here (- (point-max) (point)))
(indent
(save-excursion
- (forward-line -1)
+ (goto-char
+ (car (idlwave-commented-paragraph-beg-end)))
(idlwave-calc-hanging-indent))))
(if indent
(progn
- [elpa] externals/idlwave fa3390f48d 214/360: Added, (continued)
- [elpa] externals/idlwave fa3390f48d 214/360: Added, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave ba16611ec5 240/360: Use 'with-current-buffer' instead of save-excursion, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 971611a29d 203/360: Help details., ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 869416181d 182/360: Copyright/date, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave cc8cc7e5bf 225/360: Correct bug in help loc., ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave d3672014de 222/360: Updated dates., ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave ed5c2c4cd1 192/360: Improve error detect regexp for multi-line errors, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave d845f124b4 246/360: Use argument %s to message/error, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 677dd1d6e3 278/360: Deal with XML-parse's poor handling of underscores, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave e9d19083b8 279/360: Check for idl_catalog.xml directly., ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 985427dd6a 274/360: Calculate beginning/end of commented paragraphs.,
ELPA Syncer <=
- [elpa] externals/idlwave ed1c40082b 264/360: Finish defun (was not)., ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 5d7b645a67 262/360: Comments, whitespace, and typos. Boring., ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave bc3cbb8b06 288/360: Avoid using cl macros., ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 3932828c57 285/360: Don't use integers as anchors anymore., ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 50c75e98ca 266/360: Use custom face for debug stop line, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave cc80618cbe 348/360: port from README, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 90b181e64e 297/360: Update XML scanning for more recent IDL versions:, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 6c9137c2da 324/360: Run hooks later and wait for initial commands., ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 462aa84be4 004/360: (idlwave-surround): Added callback hook for when the previous character, ELPA Syncer, 2024/04/28
- [elpa] externals/idlwave 58078a3f5a 006/360: Cleaned ec-hook formulation in idlwave-surround., ELPA Syncer, 2024/04/28