Source

usemacs / raw-elisp / march / macos / site-lisp / wrap-it.el

Full commit
(defun wrap-it (beg end left right)
  "wrap beg to end use left and right"
  (save-excursion ((goto-char end)
                   (insert right)
                   (goto-char beg)
                   (insert left))))

(defun wrap-thing-helper (thing left right)
  "wrap these"
  (let ((contents (thing-at-point-with-bounds thing)))
       (let ((beg (car (cdr contents)))
             (end (cdr (cdr contents))))
         (wrap-it beg end left right))))

(defun wrap-thing (thing symbols)
  "wrap the thing at point"
  (interactive "Sthing:\nssymbols:\n")
  (wrap-thing-helper thing 
              (substring symbols 0 1)
              (substring symbols 1 2))
)

(defun wrap-region (symbols)
  "wrap the region"
  (interactive "ssymbols:\n")
  (wrap-it (region-beginning)
                       (region-end)
                       (substring symbols 0 1)
                       (substring symbols 1 2)))

;; it cannot work right at now
(defmacro wrap-thing-macro (thing)
  '(lambda (symbols)
     (interactive "ssymbols:\n")
     (wrap-thing-helper 'thing 
                        (substring symbols 0 1)
                        (substring symbols 1 2))))

(defun wrap-word (symbols)
  "wrap the word at point"
  (interactive "ssymbols:\n")
  (wrap-thing-helper 'word 
              (substring symbols 0 1)
              (substring symbols 1 2))
)

(defun wrap-word-quote ()
  "wrap the word at point"
  (interactive)
  (wrap-thing-helper 'word "\"" "\""))

(defun wrap-line (symbols)
  "wrap the line at point"
  (interactive "ssymbols:\n")
  (wrap-thing-helper 'line 
              (substring symbols 0 1)
              (substring symbols 1 2))
)

(defun wrap-line-quote ()
  "wrap the line at point"
  (interactive)
  (wrap-thing-helper 'line "\"" "\""))

(defun wrap-url (symbols)
  "wrap the url at point"
  (interactive "ssymbols:\n")
  (wrap-thing-helper 'url 
              (substring symbols 0 1)
              (substring symbols 1 2))
)

(defun wrap-url-quote ()
  "wrap the url at point"
  (interactive)
  (wrap-thing-helper 'url "\"" "\""))


(provide 'wrap-it)