Fork me on GitHub
#emacs
<
2016-05-20
>
lvh13:05:19

jan.zy: Interesting; for me that key is bound to append-next-kill

lvh13:05:55

(that’s just prelude)

ag19:05:33

hey… anyone has written a piece of snippet that would allow to use #_ reader macro? I’d like to comment/uncomment keybinding to work with that. it should be pretty straightforward to write, wondering if anyone already done this and I could just steal it?

zane20:05:13

I hope that exists. I also want to steal it.

ghosss21:05:46

@ag is this what you're looking for?

(defun comment-reader-macro ()
  (interactive)
  (unless (eq ?\( (following-char))
    (paredit-backward-up))
  (insert "#_"))

ghosss21:05:32

oh, uncommenting too, huh

ag21:05:07

good job @ghosss :thumbsup: :thumbsup: , now be a good lad add one for removing 🙂

ag21:05:22

(uncommenting I mean)

ghosss21:05:55

that's the tricky part, isn't it?

ag21:05:58

excuses, excuses 😄

ghosss22:05:58

I won't run this in production, but:

(defun am-i-in-a-commented-sexp ()
  (condition-case nil
      (save-excursion
        (unless (and (eq ?\( (following-char))
                     (eq ?_ (preceding-char)))
          (paredit-backward-up))
        (or (eq ?_ (preceding-char))
            (am-i-in-a-commented-sexp)))
    (error nil)))

(defun comment-uncomment-reader-macro ()
  (interactive)
  (if (am-i-in-a-commented-sexp)
      (progn
        (search-backward "#_")
        (delete-char 2))
    (progn
      (unless (eq ?\( (following-char))
        (paredit-backward-up))
      (insert "#_")))))
Uncommenting should work anywhere within the commented sexp.

ag22:05:14

cool… you are one truly awesome person… I will definitely make use of this.

ag22:05:21

I’ll try to improve it later (if I have time). for example the first function doesn’t work for other forms (maps and keywords)

ghosss22:05:44

oh right... those things 🙂

ag22:05:08

I would’ve probably used smarparens to identify current form

ghosss22:05:08

ah. I don't use that...

ghosss22:05:49

I was disappointed I was looking at characters instead of dealing with forms