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

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

[nongnu] elpa/swift-mode d900694d01: Fix current-defun-name to support q


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode d900694d01: Fix current-defun-name to support qualified name
Date: Mon, 24 Jul 2023 10:01:55 -0400 (EDT)

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

    Fix current-defun-name to support qualified name
    
    Example: `extension A<T>.B.C<U>`.
---
 swift-mode-beginning-of-defun.el | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/swift-mode-beginning-of-defun.el b/swift-mode-beginning-of-defun.el
index 0309055071..11fb3e2a3f 100644
--- a/swift-mode-beginning-of-defun.el
+++ b/swift-mode-beginning-of-defun.el
@@ -1378,9 +1378,16 @@ Interactively, the behavior depends on 
‘narrow-to-defun-include-comments’."
 (defun swift-mode:current-defun-name ()
   "Return fully qualified name of defun under the point."
   (save-excursion
-    (let ((token-list (reverse (swift-mode:current-defun-name-token-list))))
+    (let ((token-list (reverse (swift-mode:current-defun-name-token-list)))
+          text)
       (if token-list
-          (mapconcat #'swift-mode:token:text token-list ".")
+          (mapconcat (lambda (token)
+                       (setq text (swift-mode:token:text token))
+                       (if (eq (aref text 0) ?`)
+                           (substring text 1 (1- (length text)))
+                         text))
+                     token-list
+                     ".")
         nil))))
 
 (defun swift-mode:current-defun-name-token-list ()
@@ -1390,11 +1397,27 @@ The first element is the name token of the current 
defun.  The rest are the ones
 of ancestors."
   (if (bobp)
       nil
-    (let ((name-token (swift-mode:current-defun-name-token)))
-      (swift-mode:backward-sexps-until-open-curly-bracket)
+    (let ((name-token (swift-mode:current-defun-name-token))
+          name-tokens
+          next-token)
       (if name-token
-          (cons name-token (swift-mode:current-defun-name-token-list))
-        (swift-mode:current-defun-name-token-list)))))
+          (progn
+            (save-excursion
+              (swift-mode:backward-sexps-until-open-curly-bracket)
+              (setq name-tokens (swift-mode:current-defun-name-token-list)))
+            (while name-token
+              (push name-token name-tokens)
+              (goto-char (swift-mode:token:end name-token))
+              (setq next-token (swift-mode:forward-token-or-list))
+              (when (eq (swift-mode:token:type next-token) '<>)
+                (setq next-token (swift-mode:forward-token-or-list)))
+              (setq name-token
+                    (when (equal (swift-mode:token:text next-token) ".")
+                      (setq next-token (swift-mode:forward-token-or-list))
+                      (when (eq (swift-mode:token:type next-token) 'identifier)
+                        next-token))))
+            name-tokens)
+        '()))))
 
 (defun swift-mode:current-defun-name-token ()
   "Return the name token of the defun under the point."



reply via email to

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