Skip to content

Commit 9ada678

Browse files
author
Yuuki Harano
committed
Merge branch 'master' of https://github.com/emacs-mirror/emacs
2 parents ca0028f + 9ae94eb commit 9ada678

File tree

11 files changed

+316
-360
lines changed

11 files changed

+316
-360
lines changed

lisp/mail/footnote.el

Lines changed: 49 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ footnote styles."
457457
(let ((fn-regexp (footnote--current-regexp index-regexp)))
458458
(save-excursion
459459
(pcase-dolist (`(,fn ,text . ,pointers) footnote--markers-alist)
460-
;; Take care of the pointers first
460+
;; Take care of the pointers first.
461461
(dolist (locn pointers)
462462
(goto-char locn)
463463
;; Try to handle the case where `footnote-start-tag' and
@@ -505,15 +505,18 @@ footnote styles."
505505

506506
;; Internal functions
507507
(defun footnote--insert-numbered-footnote (arg &optional mousable)
508-
"Insert numbered footnote at point."
508+
"Insert numbered footnote at point.
509+
Return a marker pointing to the beginning of the [...]."
509510
(let ((string (concat footnote-start-tag
510511
(footnote--index-to-string arg)
511-
footnote-end-tag)))
512+
footnote-end-tag))
513+
(pos (point)))
512514
(insert
513515
(if mousable
514516
(propertize
515517
string 'footnote-number arg footnote-mouse-highlight t)
516-
(propertize string 'footnote-number arg)))))
518+
(propertize string 'footnote-number arg)))
519+
(copy-marker pos t)))
517520

518521
(defun footnote--renumber (to alist-elem)
519522
"Renumber a single footnote."
@@ -550,33 +553,13 @@ footnote styles."
550553
(or (re-search-backward footnote-signature-separator nil t)
551554
(point)))
552555

553-
(defun footnote--insert-text-marker (arg locn)
554-
"Insert a marker pointing to footnote ARG, at buffer location LOCN."
555-
(let ((entry (assq arg footnote--markers-alist)))
556-
(unless (cadr entry)
557-
(let ((marker (copy-marker locn t)))
558-
(if entry
559-
(setf (cadr entry) marker)
560-
(push `(,arg ,marker) footnote--markers-alist)
561-
(setq footnote--markers-alist
562-
(footnote--sort footnote--markers-alist)))))))
563-
564-
(defun footnote--insert-pointer-marker (arg locn)
565-
"Insert a marker pointing to footnote ARG, at buffer location LOCN."
566-
(let ((entry (assq arg footnote--markers-alist))
567-
(marker (copy-marker locn t)))
568-
(if entry
569-
(push marker (cddr entry))
570-
(push `(,arg nil ,marker) footnote--markers-alist)
571-
(setq footnote--markers-alist
572-
(footnote--sort footnote--markers-alist)))))
573-
574-
(defun footnote--first-text-marker ()
575-
(let ((tmp footnote--markers-alist))
576-
(while (and tmp (null (cadr (car footnote--markers-alist))))
577-
;; Skip entries which don't (yet) have a TEXT marker.
578-
(set tmp (cdr tmp)))
579-
(cadr (car tmp))))
556+
(defun footnote--insert-markers (arg text ptr)
557+
"Insert the markers of new footnote ARG."
558+
(cl-assert (and (numberp arg) (markerp text) (markerp ptr)))
559+
(cl-assert (not (assq arg footnote--markers-alist)))
560+
(push `(,arg ,text ,ptr) footnote--markers-alist)
561+
(setq footnote--markers-alist
562+
(footnote--sort footnote--markers-alist)))
580563

581564
(defun footnote--goto-first ()
582565
"Go to beginning of footnote area and return non-nil if successful.
@@ -586,42 +569,37 @@ Presumes we're within the footnote area already."
586569
(re-search-backward
587570
(concat "^" footnote-section-tag-regexp) nil t))
588571
(footnote--markers-alist
589-
(let ((pos (footnote--first-text-marker)))
590-
(when pos
591-
(goto-char pos))))))
572+
(goto-char (cadr (car footnote--markers-alist))))))
592573

593574
(defun footnote--insert-footnote (arg)
594575
"Insert a footnote numbered ARG, at (point)."
595576
(push-mark)
596-
(let ((old-point (point)))
597-
(footnote--insert-numbered-footnote arg t)
598-
(footnote--insert-pointer-marker arg old-point))
599-
(footnote--goto-char-point-max)
600-
(if (footnote--goto-first)
601-
(save-restriction
602-
(when footnote-narrow-to-footnotes-when-editing
603-
(footnote--narrow-to-footnotes))
604-
(footnote-goto-footnote (1- arg)) ; evil, FIXME (less evil now)
605-
;; (message "Inserting footnote %d" arg)
606-
(unless
607-
(or (eq arg 1)
608-
(when (re-search-forward
609-
(if footnote-spaced-footnotes
610-
"\n\n"
611-
(concat "\n" (footnote--current-regexp)))
612-
nil t)
613-
(unless (beginning-of-line) t))
614-
(footnote--goto-char-point-max)
615-
(footnote--goto-first))))
616-
(unless (looking-at "^$")
617-
(insert "\n"))
618-
(when (eobp)
619-
(insert "\n"))
620-
(unless (string-equal footnote-section-tag "")
621-
(insert footnote-section-tag "\n")))
622-
(let ((old-point (point)))
623-
(footnote--insert-numbered-footnote arg nil)
624-
(footnote--insert-text-marker arg old-point)))
577+
(let ((ptr (footnote--insert-numbered-footnote arg t)))
578+
(footnote--goto-char-point-max)
579+
(if (footnote--goto-first)
580+
(save-restriction
581+
(when footnote-narrow-to-footnotes-when-editing
582+
(footnote--narrow-to-footnotes))
583+
(footnote-goto-footnote (1- arg)) ; evil, FIXME (less evil now)
584+
;; (message "Inserting footnote %d" arg)
585+
(or (eq arg 1)
586+
(when (re-search-forward
587+
(if footnote-spaced-footnotes
588+
"\n\n"
589+
(concat "\n" (footnote--current-regexp)))
590+
nil t)
591+
(beginning-of-line)
592+
t)
593+
(footnote--goto-char-point-max)
594+
(footnote--goto-first)))
595+
(unless (looking-at "^$")
596+
(insert "\n"))
597+
(when (eobp)
598+
(insert "\n"))
599+
(unless (string-equal footnote-section-tag "")
600+
(insert footnote-section-tag "\n")))
601+
(let ((text (footnote--insert-numbered-footnote arg nil)))
602+
(footnote--insert-markers arg text ptr))))
625603

626604
(defun footnote--sort (list)
627605
(sort list #'car-less-than-car))
@@ -671,14 +649,14 @@ With optional arg BEFORE-TAG, return position of the `footnote-section-tag'
671649
instead, if applicable."
672650
(cond
673651
;; FIXME: Shouldn't we use `footnote--get-area-point-max' instead?
674-
((not (footnote--first-text-marker)) (point-max))
675-
((not before-tag) (footnote--first-text-marker))
676-
((string-equal footnote-section-tag "") (footnote--first-text-marker))
652+
((not footnote--markers-alist) (point-max))
653+
((not before-tag) (cadr (car footnote--markers-alist)))
654+
((string-equal footnote-section-tag "") (cadr (car footnote--markers-alist)))
677655
(t
678656
(save-excursion
679-
(goto-char (footnote--first-text-marker))
657+
(goto-char (cadr (car footnote--markers-alist)))
680658
(if (re-search-backward (concat "^" footnote-section-tag-regexp) nil t)
681-
(match-beginning 0)
659+
(point)
682660
(message "Footnote section tag not found!")
683661
;; This `else' should never happen, and indicates an error,
684662
;; ie. footnotes already exist and a footnote-section-tag is defined,
@@ -696,7 +674,7 @@ instead, if applicable."
696674
;; function, and repeat.
697675
;;
698676
;; TODO: integrate sanity checks at reasonable operational points.
699-
(footnote--first-text-marker))))))
677+
(point))))))
700678

701679
(defun footnote--get-area-point-max ()
702680
"Return the end of footnote area.
@@ -832,8 +810,8 @@ specified, jump to the text of that footnote."
832810
((not (string-equal footnote-section-tag ""))
833811
(re-search-backward (concat "^" footnote-section-tag-regexp))
834812
(forward-line 1))
835-
((footnote--first-text-marker)
836-
(goto-char (footnote--first-text-marker)))))
813+
(footnote--markers-alist
814+
(goto-char (cadr (car footnote--markers-alist))))))
837815
(t
838816
(error "I don't see a footnote here")))))
839817

lisp/progmodes/cc-engine.el

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ otherwise return nil and leave point unchanged.
287287

288288
Note that this function might do hidden buffer changes. See the
289289
comment at the start of cc-engine.el for more info."
290-
(let ((here (point)))
290+
(let ((here (point))
291+
(pause (c-point 'eol)))
291292
(when c-opt-cpp-prefix
292293
(if (and (car c-macro-cache)
293294
(>= (point) (car c-macro-cache))
@@ -307,8 +308,23 @@ comment at the start of cc-engine.el for more info."
307308
(save-restriction
308309
(if lim (narrow-to-region lim (point-max)))
309310
(beginning-of-line)
310-
(while (eq (char-before (1- (point))) ?\\)
311-
(forward-line -1))
311+
(when (or (null lim)
312+
(>= here lim))
313+
(while
314+
(progn
315+
(while (eq (char-before (1- (point))) ?\\)
316+
(forward-line -1))
317+
(when (and c-last-c-comment-end-on-line-re
318+
(re-search-forward
319+
c-last-c-comment-end-on-line-re pause t))
320+
(goto-char (match-end 1))
321+
(if (c-backward-single-comment)
322+
(progn
323+
(beginning-of-line)
324+
(setq pause (point)))
325+
(goto-char pause)
326+
nil)))))
327+
312328
(back-to-indentation)
313329
(if (and (<= (point) here)
314330
(save-match-data (looking-at c-opt-cpp-start))
@@ -345,12 +361,23 @@ comment at the start of cc-engine.el for more info."
345361
c-macro-cache-start-pos nil
346362
c-macro-cache-syntactic nil
347363
c-macro-cache-no-comment nil))
348-
(while (progn
349-
(end-of-line)
350-
(when (and (eq (char-before) ?\\)
351-
(not (eobp)))
352-
(forward-char)
353-
t)))
364+
(while
365+
(progn
366+
(while (progn
367+
(end-of-line)
368+
(when (and (eq (char-before) ?\\)
369+
(not (eobp)))
370+
(forward-char)
371+
t)))
372+
(if (and c-last-open-c-comment-start-on-line-re
373+
(re-search-backward
374+
c-last-open-c-comment-start-on-line-re
375+
(c-point 'bol) t))
376+
(progn
377+
(goto-char (match-beginning 1))
378+
(c-forward-single-comment))
379+
nil)))
380+
354381
(when (and (car c-macro-cache)
355382
(bolp)
356383
(not (eq (char-before (1- (point))) ?\\)))
@@ -2007,6 +2034,10 @@ comment at the start of cc-engine.el for more info."
20072034
;; Take elaborate precautions to detect an open block comment at
20082035
;; the end of a macro. If we find one, we set `safe-start' to nil
20092036
;; and break off any further scanning of comments.
2037+
;;
2038+
;; (2019-05-02): `c-end-of-macro' now moves completely over block
2039+
;; comments, even multiline ones lacking \s at their EOLs. So a
2040+
;; lot of the following is probably redundant now.
20102041
(let ((com-begin (point)) com-end in-macro)
20112042
(when (and (c-forward-single-comment)
20122043
(setq com-end (point))
@@ -5661,7 +5692,10 @@ comment at the start of cc-engine.el for more info."
56615692
(setq cfd-re-match cfd-limit)
56625693
nil)
56635694
((c-got-face-at
5664-
(if (setq cfd-re-match (match-end 1))
5695+
(if (setq cfd-re-match
5696+
(or (match-end 1)
5697+
(and c-dposr-cpp-macro-depth
5698+
(match-end (1+ c-dposr-cpp-macro-depth)))))
56655699
;; Matched the end of a token preceding a decl spot.
56665700
(progn
56675701
(goto-char cfd-re-match)
@@ -5672,15 +5706,19 @@ comment at the start of cc-engine.el for more info."
56725706
c-literal-faces)
56735707
;; Pseudo match inside a comment or string literal. Skip out
56745708
;; of comments and string literals.
5675-
(while (progn
5676-
(unless
5677-
(and (match-end 1)
5678-
(c-got-face-at (1- (point)) c-literal-faces)
5679-
(not (c-got-face-at (point) c-literal-faces)))
5680-
(goto-char (c-next-single-property-change
5681-
(point) 'face nil cfd-limit)))
5682-
(and (< (point) cfd-limit)
5683-
(c-got-face-at (point) c-literal-faces))))
5709+
(while
5710+
(progn
5711+
(unless
5712+
(and
5713+
(or (match-end 1)
5714+
(and c-dposr-cpp-macro-depth
5715+
(match-end (1+ c-dposr-cpp-macro-depth))))
5716+
(c-got-face-at (1- (point)) c-literal-faces)
5717+
(not (c-got-face-at (point) c-literal-faces)))
5718+
(goto-char (c-next-single-property-change
5719+
(point) 'face nil cfd-limit)))
5720+
(and (< (point) cfd-limit)
5721+
(c-got-face-at (point) c-literal-faces))))
56845722
t) ; Continue the loop over pseudo matches.
56855723
((and c-opt-identifier-concat-key
56865724
(match-string 1)
@@ -5832,7 +5870,7 @@ comment at the start of cc-engine.el for more info."
58325870
;; before the point, and do the first `c-decl-prefix-or-start-re'
58335871
;; search unless we're at bob.
58345872

5835-
(let (start-in-literal start-in-macro syntactic-pos)
5873+
(let (start-in-literal start-in-macro syntactic-pos hash-define-pos)
58365874
;; Must back up a bit since we look for the end of the previous
58375875
;; statement or declaration, which is earlier than the first
58385876
;; returned match.
@@ -5987,7 +6025,21 @@ comment at the start of cc-engine.el for more info."
59876025
;; The only syntactic ws in macros are comments.
59886026
(c-backward-comments)
59896027
(or (bobp) (backward-char))
5990-
(c-beginning-of-current-token))
6028+
(c-beginning-of-current-token)
6029+
;; If we're in a macro without argument parentheses, we could have
6030+
;; now ended up at the macro's identifier. We need to be at #define
6031+
;; for `c-find-decl-prefix-search' to find the first token of the
6032+
;; macro's expansion.
6033+
(when (and (c-on-identifier)
6034+
(setq hash-define-pos
6035+
(save-excursion
6036+
(and
6037+
(zerop (c-backward-token-2 2)) ; over define, #
6038+
(save-excursion
6039+
(beginning-of-line)
6040+
(looking-at c-opt-cpp-macro-define-id))
6041+
(point)))))
6042+
(goto-char hash-define-pos)))
59916043

59926044
(start-in-literal
59936045
;; If we're in a comment it can only be the closest

0 commit comments

Comments
 (0)