help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: recommended html modes


From: XeCycle
Subject: Re: recommended html modes
Date: Fri, 23 Mar 2012 23:35:34 +0800
User-agent: Gnus/5.130004 (Ma Gnus v0.4) Emacs/24.0.94 (gnu/linux)

prad <prad@towardsfreedom.com> writes:

> XeCycle <XeCycle@Gmail.com> writes:

[...]

>> A more robust way is to use add-to-list 'auto-mode-alist.
>>
> ok thx carl!
> i did it that way.

Never mind.

[...]

> inspired by your above comment, i gave this a shot - figured i'd
> better start learning elisp. :D
>
> i don't know much about interactive etc, but i found the ref
> manual and
> the gnu tutorial.
>
> here's what i got and it does work (though i don't know if it is
> a good
> way or not):
>
> ;; region wrapping with tag functions
>
> (defun tag-enclose (tag)
>   "encloses region with inputted tag"
>   (interactive "sTag: ")
>   (wrap-with-tags))
>
> (defun wrap-with-tags ()
>   "builds html tags from tag then wraps region"
>   (interactive)
>   (let* ((begend (region-parameters))
>          (beg (car begend))
>          (end (cadr begend))
>          (tagbeg (format "<%s>" tag))
>          (tagend (format "</%s>" tag)))
>     (goto-char end)
>     (insert tagend)
>     (goto-char beg)
>     (insert tagbeg)))
>
> (defun region-parameters ()
>   "gets region beg and end"
>   (interactive)
>   (list (region-beginning) (region-end)))
>
>
> i didn't do your swap idea because i haven't found that function
> yet.

Well, if you're curious, that's already bound to C-x C-x.

> however, i realized that i had to put the end tag on first,
> because as
> soon as i do the beg tag, the positions all shift forward and my
> end
> position isn't what it is supposed to be anymore. :D

The active region is always between the point and (active) mark.
When you insert text all marks after the point will be
automatically shifted accordingly.  So I suggest using the point
and mark.  Also you can have a look at (save-excursion
(save-restriction ...)).

-- 
Carl Lei (XeCycle)
Department of Physics, Shanghai Jiao Tong University
OpenPGP public key: 7795E591
Fingerprint: 1FB6 7F1F D45D F681 C845 27F7 8D71 8EC4 7795 E591

Attachment: pgp0n5NHjH2MU.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]