Skip to content

Commit

Permalink
Fix current-defun-name to support qualified name
Browse files Browse the repository at this point in the history
Example: `extension A<T>.B.C<U>`.
  • Loading branch information
taku0 committed Jul 24, 2023
1 parent 55da7a3 commit d900694
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions swift-mode-beginning-of-defun.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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."
Expand Down

0 comments on commit d900694

Please sign in to comment.