Skip to content

Instantly share code, notes, and snippets.

@roife
Last active March 26, 2019 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roife/3866d2e1428d89b5065f89c1f22121df to your computer and use it in GitHub Desktop.
Save roife/3866d2e1428d89b5065f89c1f22121df to your computer and use it in GitHub Desktop.
Use macro to simplify thing-edit.el
(defmacro thing-edit-defcopy (thing)
"Install funstions of copying for THING."
`(defun ,(intern (format "thing-edit-copy-%s" thing)) (kill-condition)
,(format "Copy %s at current point.
With the universal argument, the text will also be killed" thing)
(interactive "P")
(thing-edit ',thing kill-condition)
))
(defmacro thing-edit-defcut (thing)
"Install funstions of cutting for THING"
`(defun ,(intern (format "thing-edit-cut-%s" thing)) ()
,(format "Cut %s at current point." thing)
(interactive)
(thing-edit ',thing t)
))
(defmacro thing-edit-defreplace (thing)
"Install funstions of replacing for THING"
`(defun ,(intern (format "thing-edit-replace-%s" thing)) ()
,(format "Cut %s at current point." thing)
(interactive)
(thing-replace ',thing)
))
(defmacro thing-edit-defthing (thing)
"Install THING."
`(progn (thing-edit-defcopy ,thing)
(thing-edit-defcut ,thing)
(thing-edit-defreplace ,thing)))
;; paren
(defun paren-at-point-bounds ()
(save-excursion
(let ((pos (thing-at-point-bounds-of-list-at-point)))
(cons (1+ (car pos))
(1- (cdr pos))))))
(put 'paren 'bounds-of-thing-at-point 'paren-at-point-bounds)
;; define things
(thing-edit-defthing symbol)
(thing-edit-defthing list)
(thing-edit-defthing sexp)
(thing-edit-defthing defun)
(thing-edit-defthing filename)
(thing-edit-defthing url)
(thing-edit-defthing email)
(thing-edit-defthing uuid)
(thing-edit-defthing word)
(thing-edit-defthing sentence)
(thing-edit-defthing whitespace)
(thing-edit-defthing line)
(thing-edit-defthing number)
(thing-edit-defthing page)
(thing-edit-defthing paragraph)
(thing-edit-defthing paren)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment