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

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

Re: need help with emacs


From: Stefan Monnier
Subject: Re: need help with emacs
Date: Fri, 07 Jan 2005 17:41:18 GMT
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

> I am using TCL in EMACS. What I need right now is the ability to do newline
> and indent on a line exceeding 80 characters in addition to adding a \.
> e.g.

> Suppose I type a line:
> This is just an example for lisp in EMACS. This is an example for lisp in
> EMACS. This is an example.

> This line should be indented as follows:

> This is just an example for lisp in EMACS. This is an example for lisp in \
>     EMACS. This is an example.

> I am not sure if this can be achieved using auto-fill-mode. Maybe someone
> among you might be using this or have any idea.

You can probably get auto-fill-mode to do something like what you want.
You'll probably need something like:

   (defun my-tcl-comment-line-break-function (&optional soft)
     (if (tcl-in-string-p) (insert "\\"))
     (comment-indent-new-line soft))

   (defun my-tcl-mode-hook ()
     ...your other Tcl-mode customizations here...
     (set (make-local-variable 'comment-line-break-function)
          'my-tcl-comment-line-break-function))

   (add-hook 'tcl-mode-hook 'my-tcl-mode-hook)

But tcl-mode does not define tcl-in-string-p.  If you use Emacs-CVS (and
font-lock), you can try to use

    (defun tcl-in-string-p () (nth 3 (syntax-ppss)))

if not, you can try

    (defun tcl-in-string-p ()
      (nth 3 (parse-partial-sexp (point-min) (point))))

but that may end up being too slow if you're editing a large Tcl buffer
(syntax-ppss is much faster because it uses caching).

Another option is something like

    (defun tcl-in-string-p ()
      (save-excursion
        (let ((pos (point)))
          (beginning-of-defun)
          (nth 3 (parse-partial-sexp (point) pos)))))

which should stay reasonably fast.


        Stefan

reply via email to

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