Skip to content

Instantly share code, notes, and snippets.

@gergelypolonkai
Created January 14, 2016 16:15
Show Gist options
  • Select an option

  • Save gergelypolonkai/cf08ee8903eb24ddcd9a to your computer and use it in GitHub Desktop.

Select an option

Save gergelypolonkai/cf08ee8903eb24ddcd9a to your computer and use it in GitHub Desktop.
Add Gtk-Doc block before the current function
(defun get-point(symbol &optional arg)
"Get point, optionally running a command beforehand"
(funcall symbol arg)
(point))
(defun current-line-number()
(save-restriction
(widen)
(save-excursion
(beginning-of-line)
(1+ (count-lines 1 (point))))))
(defun list-is-on-one-line()
(let ((first (current-line-number))
(last ((lambda()
(save-excursion
(forward-list)
(current-line-number))))))
(not (= first last))))
(defun sanitize-param-list()
(while (list-is-on-one-line)
(save-excursion
(next-line)
(delete-indentation))))
(defun sanitize-param(last)
(let ((start (point)))
(search-forward (if last ")" ","))
(backward-char 1)
(beginning-of-thing 'symbol)
(kill-region start (point))
(insert "@")
(end-of-thing 'symbol)
(delete-char 1)
(insert ":")
(newline)
(insert " *")
(when (not last) (insert " "))))
(defun add-doc-comment()
(interactive)
(save-excursion
(let ((æ-current-function (which-function)))
(beginning-of-defun)
(let ((end (get-point 'forward-list))
(beg (get-point 'backward-list)))
(copy-region-as-kill beg end))
(beginning-of-defun)
(previous-line)
(when (not (looking-at "^ \\*/"))
(newline)
(insert "/**")
(newline)
(insert " * " æ-current-function ":")
(newline)
(insert " * ")
(yank)
(backward-list)
(sanitize-param-list)
(delete-char 1)
(while (looking-at "[^,)]+,")
(sanitize-param nil))
(sanitize-param 't)
(newline)
(insert " * Insert function description here")
(newline)
(insert " */")
(newline)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment