Skip to content

Commit b4e885d

Browse files
committed
lispy.el (lispy-mark-symbol): improve
* lispy.el (lispy-mark-symbol): Can mark string from the back. * lispy-test.el (lispy-mark-symbol): Add test.
1 parent b56de31 commit b4e885d

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

lispy-test.el

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,8 @@ Insert KEY if there's no command."
879879
(ert-deftest lispy-mark-symbol ()
880880
(should (string= (lispy-with "(foo |\"bar\")" (lispy-mark-symbol))
881881
"(foo ~\"bar\"|)"))
882-
;; (should (string= (lispy-with "(foo \"bar\"|)" (lispy-mark-symbol))
883-
;; "(foo ~\"bar\"|)"))
884-
)
882+
(should (string= (lispy-with "(foo \"bar|\")" (lispy-mark-symbol))
883+
"(foo ~\"bar\"|)")))
885884

886885
(ert-deftest lispy--read ()
887886
(should (equal (lispy--read "(progn

lispy.el

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -927,40 +927,45 @@ When ARG is more than 1, mark ARGth element."
927927
(defun lispy-mark-symbol ()
928928
"Mark current symbol."
929929
(interactive)
930-
(cond ((lispy--in-comment-p)
931-
(lispy--mark (lispy--bounds-comment)))
932-
((looking-at " *)* *$")
933-
(lispy--mark (lispy--bounds-dwim)))
934-
((or (looking-at "[ ]*[()]")
935-
(and (region-active-p)
936-
(looking-at "[ \n]*[()]")))
937-
(let ((pt (point)))
938-
(skip-chars-forward "() \n")
939-
(set-mark-command nil)
940-
(condition-case nil
941-
(progn
942-
(re-search-forward "[() \n]")
943-
(while (lispy--in-string-or-comment-p)
944-
(re-search-forward "[() \n]"))
945-
(backward-char 1))
946-
(error
947-
(message "No further symbols found")
948-
(deactivate-mark)
949-
(goto-char pt)))))
930+
(let (bnd)
931+
(cond ((lispy--in-comment-p)
932+
(lispy--mark (lispy--bounds-comment)))
933+
((and
934+
(not (region-active-p))
935+
(lispy--in-string-p)
936+
(= (1+ (point))
937+
(cdr (setq bnd (lispy--bounds-string)))))
938+
(lispy--mark bnd))
939+
((or (looking-at "[ ]*[()]")
940+
(and (region-active-p)
941+
(looking-at "[ \n]*[()]")))
942+
(let ((pt (point)))
943+
(skip-chars-forward "() \n")
944+
(set-mark-command nil)
945+
(condition-case nil
946+
(progn
947+
(re-search-forward "[() \n]")
948+
(while (lispy--in-string-or-comment-p)
949+
(re-search-forward "[() \n]"))
950+
(backward-char 1))
951+
(error
952+
(message "No further symbols found")
953+
(deactivate-mark)
954+
(goto-char pt)))))
950955

951-
((looking-back lispy-right)
952-
(skip-chars-backward "() \n")
953-
(set-mark-command nil)
954-
(re-search-backward "[() \n]")
955-
(while (lispy--in-string-or-comment-p)
956-
(re-search-backward "[() \n]"))
957-
(forward-char 1))
958-
959-
((region-active-p)
960-
(ignore-errors
961-
(forward-sexp)))
962-
(t
963-
(lispy--mark (lispy--bounds-dwim)))))
956+
((looking-back lispy-right)
957+
(skip-chars-backward "() \n")
958+
(set-mark-command nil)
959+
(re-search-backward "[() \n]")
960+
(while (lispy--in-string-or-comment-p)
961+
(re-search-backward "[() \n]"))
962+
(forward-char 1))
963+
964+
((region-active-p)
965+
(ignore-errors
966+
(forward-sexp)))
967+
(t
968+
(lispy--mark (lispy--bounds-dwim))))))
964969

965970
(defun lispy-kill-at-point ()
966971
"Kill the quoted string or the list that includes the point."

0 commit comments

Comments
 (0)