Skip to content

Commit

Permalink
lispy.el (lispy-mark-symbol): improve
Browse files Browse the repository at this point in the history
* lispy.el (lispy-mark-symbol): Can mark string from the back.

* lispy-test.el (lispy-mark-symbol): Add test.
  • Loading branch information
abo-abo committed Dec 14, 2014
1 parent b56de31 commit b4e885d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
5 changes: 2 additions & 3 deletions lispy-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,8 @@ Insert KEY if there's no command."
(ert-deftest lispy-mark-symbol ()
(should (string= (lispy-with "(foo |\"bar\")" (lispy-mark-symbol))
"(foo ~\"bar\"|)"))
;; (should (string= (lispy-with "(foo \"bar\"|)" (lispy-mark-symbol))
;; "(foo ~\"bar\"|)"))
)
(should (string= (lispy-with "(foo \"bar|\")" (lispy-mark-symbol))
"(foo ~\"bar\"|)")))

(ert-deftest lispy--read ()
(should (equal (lispy--read "(progn
Expand Down
71 changes: 38 additions & 33 deletions lispy.el
Original file line number Diff line number Diff line change
Expand Up @@ -927,40 +927,45 @@ When ARG is more than 1, mark ARGth element."
(defun lispy-mark-symbol ()
"Mark current symbol."
(interactive)
(cond ((lispy--in-comment-p)
(lispy--mark (lispy--bounds-comment)))
((looking-at " *)* *$")
(lispy--mark (lispy--bounds-dwim)))
((or (looking-at "[ ]*[()]")
(and (region-active-p)
(looking-at "[ \n]*[()]")))
(let ((pt (point)))
(skip-chars-forward "() \n")
(set-mark-command nil)
(condition-case nil
(progn
(re-search-forward "[() \n]")
(while (lispy--in-string-or-comment-p)
(re-search-forward "[() \n]"))
(backward-char 1))
(error
(message "No further symbols found")
(deactivate-mark)
(goto-char pt)))))
(let (bnd)
(cond ((lispy--in-comment-p)
(lispy--mark (lispy--bounds-comment)))
((and
(not (region-active-p))
(lispy--in-string-p)
(= (1+ (point))
(cdr (setq bnd (lispy--bounds-string)))))
(lispy--mark bnd))
((or (looking-at "[ ]*[()]")
(and (region-active-p)
(looking-at "[ \n]*[()]")))
(let ((pt (point)))
(skip-chars-forward "() \n")
(set-mark-command nil)
(condition-case nil
(progn
(re-search-forward "[() \n]")
(while (lispy--in-string-or-comment-p)
(re-search-forward "[() \n]"))
(backward-char 1))
(error
(message "No further symbols found")
(deactivate-mark)
(goto-char pt)))))

((looking-back lispy-right)
(skip-chars-backward "() \n")
(set-mark-command nil)
(re-search-backward "[() \n]")
(while (lispy--in-string-or-comment-p)
(re-search-backward "[() \n]"))
(forward-char 1))

((region-active-p)
(ignore-errors
(forward-sexp)))
(t
(lispy--mark (lispy--bounds-dwim)))))
((looking-back lispy-right)
(skip-chars-backward "() \n")
(set-mark-command nil)
(re-search-backward "[() \n]")
(while (lispy--in-string-or-comment-p)
(re-search-backward "[() \n]"))
(forward-char 1))

((region-active-p)
(ignore-errors
(forward-sexp)))
(t
(lispy--mark (lispy--bounds-dwim))))))

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

0 comments on commit b4e885d

Please sign in to comment.