0

Following the advice given here, I wrote the following code to enclose the text selection in phpbb italics tags :

(defun wrap-in-phpbb-italics-tag (b e)
  "does what its name says."
  (interactive "r")
  (save-excursion
      (goto-char b)
      (insert (format "[i]"))
      (goto-char e)
      (insert (format "[/i]"))))

This code almost does what I want : the left tag is positioned correctly but the right tag is three characters too early. Thus, if the selected goes Adjust end index in selected region, the result will be [i]Adjust end index in selected reg[/i]ion.

I tried to fix it as follows, replacing the (e) with (e+3) :

(defun wrap-in-phpbb-italics-tag (b e)
  "does what its name says."
  (interactive "r")
  (save-excursion
      (goto-char b)
      (insert (format "[i]"))
      (goto-char (e+3))
      (insert (format "[/i]"))))

But with this new code, the right tag simply disappears. What is going on here ? How can I fix this ?

Drew
  • 75,699
  • 9
  • 109
  • 225
Ewan Delanoy
  • 173
  • 9

1 Answers1

1

Your code contains an error: (e+3), it should be (+ e 3). When you run your command, Emacs will report the following error message in Echo Area and the *Messages* buffer

goto-char: Symbol's function definition is void: e+3

Alternatively, you can insert at the end then at the beginning, so you don't need to +3 since b isn't moved at all.

(defun wrap-in-phpbb-italics-tag (b e)
  "does what its name says."
  (interactive "r")
  (save-excursion
    (goto-char e)
    (insert "[/i]")
    (goto-char b)
    (insert "[i]")))
xuchunyang
  • 14,302
  • 1
  • 18
  • 39