emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/swift-mode 4a5f577 488/496: Tweak comments and style


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode 4a5f577 488/496: Tweak comments and style
Date: Sun, 29 Aug 2021 11:34:33 -0400 (EDT)

branch: elpa/swift-mode
commit 4a5f57722e06dad3bbbb1a496ef7d1b732ac7c46
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>

    Tweak comments and style
---
 swift-mode-beginning-of-defun.el | 60 ++++++++++++++++++++++++++++------------
 swift-mode-indent.el             |  8 ------
 swift-mode-lexer.el              |  9 ++++--
 3 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/swift-mode-beginning-of-defun.el b/swift-mode-beginning-of-defun.el
index 4c423a8..539bdcf 100644
--- a/swift-mode-beginning-of-defun.el
+++ b/swift-mode-beginning-of-defun.el
@@ -312,23 +312,27 @@ Intended for internal use."
         (previous-token (save-excursion (swift-mode:backward-token)))
         next-token)
     (cond
+     ;; Already at the end of statement.  Returns next token.
      ((and
        (memq (swift-mode:token:type previous-token)
              '(\; anonymous-function-parameter-in))
        (eq (swift-mode:token:end previous-token) pos))
-      ;; Already at the end of statement.  Returns next token.
       (save-excursion (swift-mode:forward-token)))
+
+     ;; Between statements, or before the first statement.
      ((memq (swift-mode:token:type previous-token)
             '(implicit-\; outside-of-buffer))
-      ;; Between statements, or before the first statement.
       (swift-mode:forward-statement))
+
+     ;; Already at the end of statement.  Returns next token.
      ((progn
         (setq next-token (save-excursion (swift-mode:forward-token)))
         (and (memq (swift-mode:token:type next-token)
                    '(implicit-\; } outside-of-buffer))
              (eq (swift-mode:token:end previous-token) pos)))
-      ;; Already at the end of statement.  Returns next token.
       next-token)
+
+     ;; Inside a statement.
      (t
       (swift-mode:forward-statement)))))
 
@@ -362,11 +366,19 @@ Intended for internal use."
                '\;)
       (setq token (swift-mode:forward-token)))
     (cond
+     ;; The statement is the last one in the buffer.
+     ;; Goes back to the end of the statement unless we were between the end of
+     ;; the statement and the end of the buffer.
      ((eq (swift-mode:token:type token) 'outside-of-buffer)
       (forward-comment (- (point)))
       (when (<= (point) pos)
         (goto-char (swift-mode:token:end token)))
       token)
+
+     ;; We were inside of a block.
+     ;; Goes back to the end of the statement unless we were between the end of
+     ;; the statement and the close bracket.
+     ;; Otherwise, goes to the end of the parent statement.
      ((eq (swift-mode:token:type token) '})
       (forward-comment (- (point)))
       (if (<= (point) pos)
@@ -374,6 +386,8 @@ Intended for internal use."
             (goto-char (swift-mode:token:end token))
             (swift-mode:end-of-statement))
         token))
+
+     ;; Otherwise, we have finished.
      (t token))))
 
 (defun swift-mode:end-of-defun (&optional arg)
@@ -559,7 +573,6 @@ MOVE-BACKWARD is a function moving the cursor to the 
previous beginning of
 block.
 Both functions return t if succeeded, return nil otherwise."
   (setq arg (or arg 1))
-
   (let ((reversed (< arg 0))
         (count (abs arg))
         (direction
@@ -587,10 +600,8 @@ Both functions return t if succeeded, return nil 
otherwise."
              ((eq direction 'containing) 'containing)
              ((eq direction 'preceding) 'following)
              ((eq direction 'following) 'preceding))))
-
     (setq new-region original-region)
     (setq new-direction direction)
-
     (while (and new-region (< 0 count))
       (let ((new-region-and-direction
              (swift-mode:extend-region-to-be-marked
@@ -604,16 +615,13 @@ Both functions return t if succeeded, return nil 
otherwise."
       (when new-region
         (setq last-successful-region new-region))
       (setq count (1- count)))
-
     (setq new-region (or new-region last-successful-region))
     (setq swift-mode:last-mark-direction new-direction)
-
     (and
      new-region
      (progn
        (goto-char (car new-region))
        (push-mark (cdr new-region) nil t)
-
        (if (eq (car original-region) (cdr original-region))
            (when (eq new-direction 'preceding)
              (exchange-point-and-mark))
@@ -838,9 +846,11 @@ Both functions return t if succeeded, return nil 
otherwise."
               (nth 0 (swift-mode:containing-generic-block-region
                       (cons (point) (point))
                       move-forward move-backward)))
+
              ((eq swift-mode:mark-defun-preference 'preceding)
               (swift-mode:preceding-generic-block-region
                move-forward move-backward))
+
              ((eq swift-mode:mark-defun-preference 'following)
               (swift-mode:following-generic-block-region
                move-forward move-backward))))
@@ -885,28 +895,31 @@ Return t if a sentence is found.  Return nil otherwise."
 In comments or strings, skip a sentence.  Otherwise, skip a statement."
   (let ((chunk (swift-mode:chunk-after)))
     (cond
+     ;; Inside a comment.
      ((swift-mode:chunk:comment-p chunk)
       (swift-mode:forward-sentence-inside-comment
        (swift-mode:chunk:single-line-comment-p chunk)))
+
+     ;; Inside a string.
      ((swift-mode:chunk:string-p chunk)
       (swift-mode:forward-sentence-inside-string))
+
      ;; Spaces at the beginning of 2nd and following lines.
+     ;; Between the beginning of the line and "ccc" and "ddd" bellow:
      ;;
      ;; class Foo {
      ;;   // aaa
      ;;
      ;;   // bbb
-     ;;   // ccc ← spaces before //
-     ;;   // ddd ← spaces before //
+     ;;   // ccc
+     ;;   // ddd
      ;;   func foo() { // eee
      ;;   }
      ;; }
      ;;
-     ;; Not including spaces before the first line of blocks.
+     ;; Not including spaces before the first line of blocks ("bbb").
      ((save-excursion
         (skip-syntax-backward " ")
-        (skip-chars-backward "/")
-        (skip-syntax-backward " ")
         (and (bolp)
              (looking-at "[ \t]*//")
              (not (bobp))
@@ -917,6 +930,8 @@ In comments or strings, skip a sentence.  Otherwise, skip a 
statement."
       (skip-syntax-forward " ")
       (forward-char 2)
       (swift-mode:forward-sentence-inside-comment t))
+
+     ;; Otherwise
      (t
       (swift-mode:forward-sentence-inside-code)))))
 
@@ -926,24 +941,29 @@ In comments or strings, skip a sentence.  Otherwise, skip 
a statement."
 In comments or strings, skip a sentence.  Otherwise, skip a statement."
   (let ((chunk (swift-mode:chunk-after)))
     (cond
+     ;; Inside a comment.
      ((swift-mode:chunk:comment-p chunk)
       (swift-mode:backward-sentence-inside-comment
        (swift-mode:chunk:single-line-comment-p chunk)))
+
+     ;; Inside a string.
      ((swift-mode:chunk:string-p chunk)
       (swift-mode:backward-sentence-inside-string))
+
      ;; Spaces at the beginning of 2nd and following lines.
+     ;; Between the beginning of the line and "ccc" and "ddd" bellow:
      ;;
      ;; class Foo {
      ;;   // aaa
      ;;
      ;;   // bbb
-     ;;   // ccc ← spaces before //
-     ;;   // ddd ← spaces before //
+     ;;   // ccc
+     ;;   // ddd
      ;;   func foo() { // eee
      ;;   }
      ;; }
      ;;
-     ;; Not including spaces before the first line of blocks.
+     ;; Not including spaces before the first line of blocks ("bbb").
      ((save-excursion
         (skip-syntax-backward " ")
         (and (bolp)
@@ -951,11 +971,13 @@ In comments or strings, skip a sentence.  Otherwise, skip 
a statement."
              (not (bobp))
              (progn
                (backward-char)
-               (nth 4 (syntax-ppss)))))
+               (swift-mode:chunk:comment-p (swift-mode:chunk-after)))))
       (forward-line 0)
       (skip-syntax-forward " ")
       (forward-char 2)
       (swift-mode:backward-sentence-inside-comment t))
+
+     ;; Otherwise
      (t
       (swift-mode:backward-sentence-inside-code)))))
 
@@ -1210,8 +1232,10 @@ of lines.  Empty lines split blocks.  Example:
             (skip-chars-forward "\"")
             (skip-syntax-forward " >")
             t)
+
            ((eq (char-after) ?\))
             (swift-mode:backward-sentence-inside-interpolated-expression))
+
            (t
             (swift-mode:backward-sentence-inside-code t)))))))
 
diff --git a/swift-mode-indent.el b/swift-mode-indent.el
index ea898c0..ce942a6 100644
--- a/swift-mode-indent.el
+++ b/swift-mode-indent.el
@@ -152,7 +152,6 @@ declaration and its offset is `swift-mode:basic-offset'."
 (defun swift-mode:calculate-indent ()
   "Return the indentation of the current line."
   (back-to-indentation)
-
   (let ((parser-state (syntax-ppss)))
     (cond
      ((nth 4 parser-state)
@@ -1616,7 +1615,6 @@ See `indent-new-comment-line' for SOFT."
          (comment-beginning-position (swift-mode:chunk:start chunk)))
     (if soft (insert-and-inherit ?\n) (newline 1))
     (delete-horizontal-space)
-
     ;; Inserts a prefix and indents the line.
     (cond
      ((not (swift-mode:chunk:comment-p chunk))
@@ -1646,7 +1644,6 @@ See `indent-new-comment-line' for SOFT."
 
      (t
       (swift-mode:format-multiline-comment-line-after-newline chunk soft)))
-
     ;; Cleans up the previous line.
     (save-excursion
       (forward-line 0)
@@ -1750,7 +1747,6 @@ See `indent-new-comment-line' for SOFT."
      (t
       ;; Uses the default indentation.
       (indent-according-to-mode)))
-
     ;; Closes incomplete multiline comment.
     (when (and swift-mode:auto-close-multiline-comment
                (swift-mode:incomplete-comment-p chunk))
@@ -1760,7 +1756,6 @@ See `indent-new-comment-line' for SOFT."
           (if soft (insert-and-inherit ?\n) (newline 1)))
         (insert-and-inherit "*/")
         (indent-according-to-mode)))
-
     ;; Make sure the closing delimiter is on its own line.
     (when swift-mode:break-line-before-comment-close
       (save-excursion
@@ -1839,12 +1834,9 @@ See `indent-new-comment-line' for SOFT."
    swift-mode:anchor-overlay
    (swift-mode:indentation:point indentation)
    (1+ (swift-mode:indentation:point indentation)))
-
   (overlay-put swift-mode:anchor-overlay 'face 'highlight)
-
   (when swift-mode:anchor-overlay-timer
     (cancel-timer swift-mode:anchor-overlay-timer))
-
   (let ((buffer (current-buffer)))
     (setq swift-mode:anchor-overlay-timer
           (run-at-time
diff --git a/swift-mode-lexer.el b/swift-mode-lexer.el
index f9641bf..400410e 100644
--- a/swift-mode-lexer.el
+++ b/swift-mode-lexer.el
@@ -243,7 +243,6 @@ Intended for `syntax-propertize-function'."
      ((swift-mode:chunk:comment-p chunk)
       (goto-char (swift-mode:chunk:start chunk))
       (forward-comment (point-max)))))
-
   (swift-mode:syntax-propertize:scan end 0))
 
 (defun swift-mode:syntax-propertize:scan (end nesting-level)
@@ -317,6 +316,7 @@ pound signs."
         (put-text-property (1- (point)) (point)
                            'syntax-table
                            (string-to-syntax "|")))
+
        ((and (equal "(" (match-string-no-properties 0))
              (swift-mode:escaped-p (match-beginning 0) pound-count))
         ;; Found an interpolated expression. Skips the expression.
@@ -352,6 +352,7 @@ pound signs."
                                (1- (point)))
             (swift-mode:syntax-propertize:end-of-string
              end quotation pound-count))))
+
        (t
         (swift-mode:syntax-propertize:end-of-string end quotation 
pound-count)))
     (goto-char end)))
@@ -700,7 +701,6 @@ Return nil otherwise."
       nil
     (save-excursion
       (setq swift-mode:in-recursive-call-of-case-colon-p t)
-
       (unwind-protect
           (member
            ;; FIXME:
@@ -1419,14 +1419,19 @@ If PARSER-STATE is given, it is used instead of 
(syntax-ppss)."
                           (looking-at "#*\"\"\""))
           (swift-mode:chunk 'multiline-string (nth 8 parser-state))
         (swift-mode:chunk 'single-line-string (nth 8 parser-state))))
+
      ((eq (nth 4 parser-state) t)
       (swift-mode:chunk 'single-line-comment (nth 8 parser-state)))
+
      ((nth 4 parser-state)
       (swift-mode:chunk 'multiline-comment (nth 8 parser-state)))
+
      ((and (eq (char-before) ?/) (eq (char-after) ?/))
       (swift-mode:chunk 'single-line-comment (1- (point))))
+
      ((and (eq (char-before) ?/) (eq (char-after) ?*))
       (swift-mode:chunk 'multiline-comment (1- (point))))
+
      (t
       nil))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]