Download
(require 'thingatpt)
(defun thing-edit-internal (object-beg object-end &optional kill-conditional)
"A fast edit complexes object.
Argument OBJECT-BEG the begin position that object.
Argument OBJECT-END the end position of object.
Optional argument KILL-CONDITIONAL default is do copy handle, if KILL-CONDITIONAL is non-nil do paste handle."
(interactive)
(if kill-conditional
(progn
(message "%s pasted." (buffer-substring object-beg object-end))
(kill-region object-beg object-end))
(message "%s copied." (buffer-substring object-beg object-end))
(kill-ring-save object-beg object-end)))
(defun thing-edit (thing &optional kill-conditional)
"This function is a simple interface for `thing-edit-internal'.
If `KILL-CONDITIONAL' is non-nil, kill object,
otherwise copy object."
(save-excursion
(thing-edit-internal (beginning-of-thing thing)
(end-of-thing thing)
kill-conditional)))
(defun thing-paste-sexp ()
"Paste regular expression at current point."
(interactive)
(thing-edit 'sexp t))
(defun thing-copy-sexp ()
"Copy regular expression at current point."
(interactive)
(thing-edit 'sexp))
(defun thing-paste-email ()
"Paste email at current point."
(interactive)
(thing-edit 'email t))
(defun thing-copy-email ()
"Copy email at current point."
(interactive)
(thing-edit 'email))
(defun thing-paste-filename ()
"Paste filename at current point."
(interactive)
(thing-edit 'filename t))
(defun thing-copy-filename ()
"Copy filename at current point."
(interactive)
(thing-edit 'filename))
(defun thing-paste-url ()
"Paste url at current point."
(interactive)
(thing-edit 'url t))
(defun thing-copy-url ()
"Copy url at current point."
(interactive)
(thing-edit 'url))
(defun thing-paste-word ()
"Paste words at point."
(interactive)
(thing-edit 'word t))
(defun thing-copy-word ()
"Copy words at point."
(interactive)
(thing-edit 'word))
(defun thing-paste-symbol ()
"Paste symbol around point."
(interactive)
(thing-edit 'symbol t))
(defun thing-copy-symbol ()
"Copy symbol around point."
(interactive)
(thing-edit 'symbol))
(defun thing-paste-line ()
"Paste current line into Kill-Ring without mark the line."
(interactive)
(thing-edit 'line t))
(defun thing-copy-line ()
"Copy current line into Kill-Ring without mark the line."
(interactive)
(thing-edit 'line))
(defun thing-paste-defun ()
"Paste function around point."
(interactive)
(thing-edit 'defun t))
(defun thing-copy-defun ()
"Paste function around point."
(interactive)
(thing-edit 'defun))
(defun thing-paste-list ()
"Paste list around point."
(interactive)
(thing-edit 'list t))
(defun thing-copy-list ()
"Paste list around point."
(interactive)
(thing-edit 'list))
(defun thing-paste-sentence ()
"Paste sentence around point."
(interactive)
(thing-edit 'sentence t))
(defun thing-copy-sentence ()
"Paste sentence around point."
(interactive)
(thing-edit 'sentence))
(defun thing-paste-whitespace ()
"Paste whitespace around point."
(interactive)
(thing-edit 'whitespace t))
(defun thing-copy-whitespace ()
"Paste whitespace around point."
(interactive)
(thing-edit 'whitespace))
(defun thing-paste-page ()
"Paste page around point."
(interactive)
(thing-edit 'page t))
(defun thing-copy-page ()
"Paste page around point."
(interactive)
(thing-edit 'page))
(defun thing-paste-to-line-end ()
"Paste content from current point to line end."
(interactive)
(thing-copy-to-line-end t))
(defun thing-copy-to-line-end (&optional kill-conditional)
"Copy content from current point to line end.
If `KILL-CONDITIONAL' is non-nil, kill object,
otherwise copy object."
(interactive)
(save-excursion
(thing-edit-internal (point)
(line-end-position)
kill-conditional)))
(defun thing-paste-to-line-beginning ()
"Paste content from current point to line beginning."
(interactive)
(thing-copy-to-line-beginning t))
(defun thing-copy-to-line-beginning (&optional kill-conditional)
"Copy content from current point tot line beginning.
If `KILL-CONDITIONAL' is non-nil, kill object,
otherwise copy object."
(interactive)
(save-excursion
(thing-edit-internal (line-beginning-position)
(point)
kill-conditional)))
(defun thing-paste-comment ()
"Paste the comment around line.
If mark is active, it can paste all comment that in mark."
(interactive)
(thing-copy-comment t))
(defun thing-copy-comment (&optional kill-conditional)
"Copy the comment around line.
If mark is active, it can copy all comment that in mark.
If `KILL-CONDITIONAL' is non-nil, kill object,
otherwise copy object."
(interactive)
(let ((beg (line-beginning-position))
(end (line-end-position)))
(when mark-active
(setq beg (region-beginning))
(setq end (region-end))
(deactivate-mark))
(save-excursion
(setq end (copy-marker end))
(goto-char beg)
(while (< (point) end)
(if (comment-search-forward end t)
(if kill-conditional
(call-interactively 'comment-kill)
(call-interactively 'comment-copy))
(goto-char end))))))
(provide 'thing-edit)