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

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

[nongnu] elpa/typescript-mode a2167a133d 056/222: Fix errors with indent


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode a2167a133d 056/222: Fix errors with indentation when line has wide unicode chars.
Date: Sun, 6 Feb 2022 16:59:14 -0500 (EST)

branch: elpa/typescript-mode
commit a2167a133dfc7042d931a80c34439f38c06e756d
Author: Jostein Kjønigsen <jostein@kjonigsen.net>
Commit: Jostein Kjønigsen <jostein@kjonigsen.net>

    Fix errors with indentation when line has wide unicode chars.
    
    This closes https://github.com/ananthakumaran/typescript.el/issues/33.
---
 typescript-mode-tests.el | 7 +++++++
 typescript-mode.el       | 9 ++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index 0c8fec5076..6e135f8090 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -99,6 +99,13 @@ a severity set to WARNING, no rule name."
     (should (string-equal (nth 4 matches) "1"))
     (should (string-equal (nth 5 matches) "83"))))
 
+(ert-deftest correctly-accounts-wide-chars-as-1-char ()
+  "Otsuka Ai and other multi-char users should be a happy to write typescript."
+
+  (with-temp-buffer
+    (insert "大塚愛")
+    (should (equal 3 (typescript-current-column)))))
+
 (provide 'typescript-mode-tests)
 
 ;;; typescript-mode-tests.el ends here
diff --git a/typescript-mode.el b/typescript-mode.el
index 12c71a9897..f4465495dd 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -1795,6 +1795,13 @@ nil."
            (+ typescript-indent-level typescript-expr-indent-offset))
           (t 0))))
 
+(defun typescript-current-column ()
+  "Unicode aware version of `CURRENT-COLUMN' which correctly accounts for wide 
characters."
+
+  (let* ((end (point)))
+    (move-beginning-of-line nil)
+    (- end (point))))
+
 (defun typescript-indent-line ()
   "Indent the current line as typescript."
   (interactive)
@@ -1802,7 +1809,7 @@ nil."
     (widen)
     (let* ((parse-status
             (save-excursion (syntax-ppss (point-at-bol))))
-           (offset (- (current-column) (current-indentation))))
+           (offset (- (typescript-current-column) (current-indentation))))
       (indent-line-to (typescript--proper-indentation parse-status))
       (when (> offset 0) (forward-char offset)))))
 



reply via email to

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