Fork me on GitHub
#spacemacs
<
2019-08-08
>
Abhinav Sharma11:08:38

Guys, I need you help regarding a snippet. What I'd like to do is to fold all the occurences of (comment ... ) in the file. I'm not so good at elisp so could you please help me out? I know that the z r works on the entire file and unfolds however the opposite would be nice as well.

practicalli-john13:08:37

@abhi18av my elisp is not that great sorry. Hopefully someone else can suggest something. Are you not able to put all your commented out code in a single (comment ,,, ) block at the end of your namespace, then you can just use z c to fold the comment function call. This is a fairly common 'design journal' style approach. I use the comment reader macro myself, #_, rather than the comment function, as it returns no value. Its very useful as a temporary comment within the code

Abhinav Sharma17:08:25

@jr0cket, actually as of now I'm taking the following route

(def all-defs-info-final
  (map info-for-a-def all-defs-in-src))

(comment
  (first all-defs-info-final)
  (take 10 all-defs-info-final))

This lets me keep the experimental code along with the main code itself, though it does make the file really dense. And yes #_, is something I've also become very fond of 🙂

👍 4
Abhinav Sharma16:08:44

@jr0cket, so I actually found a solution to his 🙂

(defun qyh/clojure-close-comments (arg)
  "Close all top level (comment) forms. With universal arg, open all."
  (interactive "P")
  (save-excursion
    (goto-char (point-min))
    (while (search-forward-regexp "^(comment\\>" nil 'noerror)
      (call-interactively
       (if arg 'evil-open-fold
         'evil-close-fold)))))

(evil-define-key 'normal clojure-mode-map
  "zC" 'qyh/clojure-close-comments
  "zO" (lambda () (interactive) (qyh/clojure-close-comments 'open)))

This was graciously shared with me on the spacemacs issues discussion. Hope it helps people here as well.

❤️ 8
Abhinav Sharma16:08:44

@jr0cket, so I actually found a solution to his 🙂

(defun qyh/clojure-close-comments (arg)
  "Close all top level (comment) forms. With universal arg, open all."
  (interactive "P")
  (save-excursion
    (goto-char (point-min))
    (while (search-forward-regexp "^(comment\\>" nil 'noerror)
      (call-interactively
       (if arg 'evil-open-fold
         'evil-close-fold)))))

(evil-define-key 'normal clojure-mode-map
  "zC" 'qyh/clojure-close-comments
  "zO" (lambda () (interactive) (qyh/clojure-close-comments 'open)))

This was graciously shared with me on the spacemacs issues discussion. Hope it helps people here as well.

❤️ 8