dhilst

My first elisp function

;; This is my first elisp function, it helps me to write functions
;; that surround text by HTML tags.
(defun surround-by-tag (begin end topen tclose)
"Surround selected text by HTML tags"
(goto-char begin)
(insert topen)
(goto-char (+ end (length topen)))
(insert tclose))


;; Here is how to use it. I define a function and calls
;; surround-by-tag passing the begin and end of my selection
;; as the open and close tags.
(defun p (b e)
"Surround text by <p></p>"
(interactive "r")
(surround-by-tag b e "<p>" "</p>"))

(defun pre (b e)
"Surround text by <pre></pre>"
(interactive "r")
(surround-by-tag b e "<pre>" "</pre>"))


;; Then I select my text and use the defined interactive function
;; <p>Hello elisp world</p>