[ESS-bugs] ess-mode 5.3.8; after-change-functions; RET at end of file

Markus Triska markus.triska at gmx.at
Fri Nov 28 06:05:27 CET 2008


Hi Martin,

Martin Maechler <maechler at stat.math.ethz.ch> writes:

> Hmm, thanks for the report.
> Unfortunately I (and others) have repeatedly found that the
>  text <-> code   mode switching for editing Rnw files, has
> sometimes been behaving "illogically" / "stubornly" / ....
>
> I have never started trying to find out how to fix it.
> If you (or anyone in ESS-core {which is listening to ESS-bugs})
> have time  or know of someone else (smart in Emacs & Emacs lisp)
> who'd have, we'd be very glad for helping hands...

It seems that only a few calls of `noweb-update-chunk-vector' are
missing. Adding such a (wrapped) call to `after-change-functions' fixes
the problem I reported, and probably other similar cases you found:

   (defun my-update-chunk-vector (&rest any) ; ignore arguments
     (noweb-update-chunk-vector))
   (add-hook 'after-change-functions 'my-update-chunk-vector nil t)

For my use cases, I did not notice any slowdown; however, if you find
that too slow, I think it could be improved by adding code to
`before-change-functions' that checks whether a chunk boundary is
affected by that change, and only if yes, schedules a call of
`noweb-update-chunk-vector' to be called in `after-change-functions'.

For the concrete case I reported, I also found a much simpler fix, which
I think also improves the general use case: I changed `noweb-electric-<'
to also insert a matching "@ " in addition to "<<>>=", which has so far
always been what I have inserted manually afterwards anyways:

diff --git a/lisp/noweb-mode.el b/lisp/noweb-mode.el
index 7458e3f..2e4e2a1 100644
--- a/lisp/noweb-mode.el
+++ b/lisp/noweb-mode.el
@@ -1171,7 +1171,7 @@ and and update the chunk vector."
         (progn
           (insert "<<")
           (save-excursion
-            (insert ">>=")
+            (insert ">>=\n@ ")
             (if (not (looking-at "\\s *$"))
                 (newline)))
           (noweb-update-chunk-vector))

When I then undo the change made by "<", I'm back to LaTeX mode.

All the best,
Markus



More information about the ESS-bugs mailing list