Skip to content

Automatic f-strings #132

Answered by KaratasFurkan
danlamanna asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the snippet. I changed it a little bit, make it even more smarter (i guess).

Code:

;;;; Smart f-strings
  ;; https://github.com/ubolonton/emacs-tree-sitter/issues/52
  (defun fk/python-f-string-ify (&rest _)
    ;; Does nothing if major-mode is not python or point is not on a string.
    (when-let* ((python-mode-p (eq major-mode 'python-mode))
                (str (tree-sitter-node-at-point 'string))
                (text (ts-node-text str)))
      (let ((is-f-string (string-match-p "^[bru]*f+[bru]*\\(\"\\|'\\)" text))
            (should-f-string (and (s-contains-p "{" text)
                                  (s-contains-p "}" text))))
        (if should-f-string
            (u…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ubolonton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #52 on March 19, 2021 11:33.