@@ -1811,12 +1811,78 @@ visit the new file."
1811
1811
(insert-parentheses )
1812
1812
(goto-char old-point)))
1813
1813
(t
1814
+ (when (rust-in-str)
1815
+ (rust--up-list -1 t t ))
1814
1816
(insert " (" )
1815
1817
(forward-sexp )
1816
1818
(insert " )" )
1817
1819
(backward-sexp )))
1818
1820
(insert " dbg!" ))
1819
1821
1822
+ (defun rust--up-list (&optional arg escape-strings no-syntax-crossing )
1823
+ " Compatibility for emacs 24."
1824
+ (or arg (setq arg 1 ))
1825
+ (let ((inc (if (> arg 0 ) 1 -1 ))
1826
+ (pos nil ))
1827
+ (while (/= arg 0 )
1828
+ (condition-case err
1829
+ (save-restriction
1830
+ ; ; If we've been asked not to cross string boundaries
1831
+ ; ; and we're inside a string, narrow to that string so
1832
+ ; ; that scan-lists doesn't find a match in a different
1833
+ ; ; string.
1834
+ (when no-syntax-crossing
1835
+ (let* ((syntax (syntax-ppss ))
1836
+ (string-comment-start (nth 8 syntax)))
1837
+ (when string-comment-start
1838
+ (save-excursion
1839
+ (goto-char string-comment-start)
1840
+ (narrow-to-region
1841
+ (point )
1842
+ (if (nth 3 syntax) ; in string
1843
+ (condition-case nil
1844
+ (progn (forward-sexp ) (point ))
1845
+ (scan-error (point-max )))
1846
+ (forward-comment 1 )
1847
+ (point )))))))
1848
+ (if (null forward-sexp-function)
1849
+ (goto-char (or (scan-lists (point ) inc 1 )
1850
+ (buffer-end arg)))
1851
+ (condition-case err
1852
+ (while (progn (setq pos (point ))
1853
+ (forward-sexp inc)
1854
+ (/= (point ) pos)))
1855
+ (scan-error (goto-char (nth (if (> arg 0 ) 3 2 ) err))))
1856
+ (if (= (point ) pos)
1857
+ (signal 'scan-error
1858
+ (list " Unbalanced parentheses" (point ) (point ))))))
1859
+ (scan-error
1860
+ (let ((syntax nil ))
1861
+ (or
1862
+ ; ; If we bumped up against the end of a list, see whether
1863
+ ; ; we're inside a string: if so, just go to the beginning
1864
+ ; ; or end of that string.
1865
+ (and escape-strings
1866
+ (or syntax (setf syntax (syntax-ppss )))
1867
+ (nth 3 syntax)
1868
+ (goto-char (nth 8 syntax))
1869
+ (progn (when (> inc 0 )
1870
+ (forward-sexp ))
1871
+ t ))
1872
+ ; ; If we narrowed to a comment above and failed to escape
1873
+ ; ; it, the error might be our fault, not an indication
1874
+ ; ; that we're out of syntax. Try again from beginning or
1875
+ ; ; end of the comment.
1876
+ (and no-syntax-crossing
1877
+ (or syntax (setf syntax (syntax-ppss )))
1878
+ (nth 4 syntax)
1879
+ (goto-char (nth 8 syntax))
1880
+ (or (< inc 0 )
1881
+ (forward-comment 1 ))
1882
+ (setf arg (+ arg inc)))
1883
+ (signal (car err) (cdr err))))))
1884
+ (setq arg (- arg inc)))))
1885
+
1820
1886
;;;### autoload
1821
1887
(defun rust-dbg-wrap-or-unwrap ()
1822
1888
" Either remove or add the dbg! macro."
0 commit comments