Hi Arash,

>>>>> Arash Esbati <[email protected]> writes:
> AUCTeX relies for filling on the function `fill-delete-newlines' (see
> `LaTeX-fill-region-as-para-do').  So this is what we get from Emacs.
> Try this snippet in a .tex file:
> % - Start
> }  Test

> % - Start
> } Test

> % - Start
> }                     Test

> Now eval this function and run it in your .tex file:
> (defun fill-delete-newlines-test ()
>   (let (s e)
>     (save-excursion
>       (goto-char (point-min))
>       (while (search-forward "% - Start" nil t)
>         (forward-line)
>         (setq s (point))
>         (setq e (line-end-position))
>         (fill-delete-newlines s e nil nil nil)))))

> I see:
> % - Start
> }Test

> % - Start
> } Test

> % - Start
> }Test

Thanks for your analysis. I reached `canonically-space-region' tracking
down the issue.
If I change its last part as follows (emacs 30.2), one space is retained
between "}" and "Test" for me.
----------------------------------------------------------------------
(defun canonically-space-region (beg end)
  "Remove extra spaces between words in region.
Leave one space between words, two at end of sentences or after colons
\(depending on values of `sentence-end-double-space', `colon-double-space',
and `sentence-end-without-period').
Remove indentation from each line."
  (interactive "*r")
  ;; Ideally, we'd want to scan the text from the end, so that changes to
  ;; text don't affect the boundary, but the regexp we match against does
  ;; not match as eagerly when matching backward, so we instead use
  ;; a marker.
  (unless (markerp end) (setq end (copy-marker end t)))
  (let ((end-spc-re (concat "\\(" (sentence-end) "\\) *\\|  +")))
    (save-excursion
      (goto-char beg)
      ;; Nuke tabs; they get screwed up in a fill.
      ;; This is quick, but loses when a tab follows the end of a sentence.
      ;; Actually, it is difficult to tell that from "Mr.\tSmith".
      ;; Blame the typist.
      (subst-char-in-region beg end ?\t ?\s)
      (while (and (< (point) end)
                  (re-search-forward end-spc-re end t))
        (delete-region
         (cond
          ;; `sentence-end' matched and did not match all spaces.
          ;; I.e. it only matched the number of spaces it needs: drop the rest.
          ((and (match-end 1) (> (match-end 0) (match-end 1)))  (match-end 1))
          ;; `sentence-end' matched but with nothing left.  Either that means
          ;; nothing should be removed, or it means it's the "old-style"
          ;; sentence-end which matches all it can.  Keep only 2 spaces.
          ;; We probably don't even need to check `sentence-end-double-space'.
          ((match-end 1)
           (min (match-end 0)
                (+ (if sentence-end-double-space 2 1)
                   (save-excursion (goto-char (match-end 0))
                                   (skip-chars-backward " ")
                                   (point)))))
          (t ;; It's not an end of sentence.
           (+ (match-beginning 0)
              ;; Determine number of spaces to leave:
              (save-excursion
                (skip-chars-backward " ]})\"'")
                (cond ((and sentence-end-double-space
                            (or (memq (preceding-char) '(?. ?? ?!))
                                (and sentence-end-without-period
                                     (= (char-syntax (preceding-char)) ?w)))) 2)
                      ((and colon-double-space
                            (= (preceding-char) ?:))  2)
;                     ((char-equal (preceding-char) ?\n)  0)
                      ((char-equal (preceding-char) ?\n)  1) ; CHANGED
                      (t 1))))))
         (match-end 0))))))
----------------------------------------------------------------------
I haven't understood the former part of its `end-spc-re', namely 
(concat "\\(" (sentence-end) "\\) *"), but in myopinion, it isn't
appropriate for the rest part, namely "  +", to delete the entire
matched string; we have to leave one space there.

Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopGenocide #CeasefireNOW
#IProtestAgainstTrumpAndNetanyahu'sAttackOnIran,WhichViolatesInternationalLaw



_______________________________________________
bug-auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-auctex
  • bug#81565:... Werner LEMBERG
    • bug#8... Arash Esbati
      • b... Ikumi Keita
        • ... Arash Esbati
          • ... Ikumi Keita
            • ... Stefan Monnier via bug-auctex via Bug reporting list for AUCTeX
              • ... Arash Esbati

Reply via email to