hello!
I did a little function that checked the font lock properties to see if
it is a comment or what.
depending on that information it switches the abbrev mode on or off.
it works fairly well, but is admittedly a hack. i mailed it to the list
some time ago,
but I attach it here again.
/Joakim
Phillip Lord wrote:
>
> >>>>> "Glen" == Glen Cordrey <[EMAIL PROTECTED]> writes:
>
> Glen> Does anyone know of a way to disable the insertion of
> Glen> templates within comments? For example, if I have a 'for'
> Glen> template and type in a java file
>
> Glen> /** This is for
>
> Glen> the template gets inserted when I type in the comment, which
> Glen> is obviously not what I want.
>
>
> If you are using jde-cflow to insert the templates there is
> not a trivial way to do this. jde-cflow uses abbreviation mode to
> trigger the insertion of templates. Switching on abbrev mode affects
> the entire buffer. The same is true for the JDE mode abbreviation
> expansion.
>
> There are a couple of possible solutions to the problem.
>
> The one which I use is to re-define the abbreviations to
> things which are not words. I've done this for both the jde-cflow, and
> jde abbreviations. So I use "foi" to get an incrementing for loop,
> "fod" to get a decrementing one, "ret" instead of the standard "re"
> for "return. If you want to try this I suggest that you try the
> updated version of jde-cflow that I wrote which allows you to use
> customize to change the templates, and abbreviations (available at
> genetics.ich.ucl.ac.uk/plord).
>
> Second would be to switch abbrev mode off, and use C-x a e
> (expand-abbrev) to manually expand the abbreviation before the point.
>
> Finally if you are into lisp there is a hook,
> pre-abbrev-expand-hook which you could use to check to see if you were
> within a comment (using the syntax information available from C mode)
> to abort the expansion, by throwing an error I guess.
>
> Its an interesting point here. It would be nice to be able to
> switch on and off minor modes depending on the syntax info. For
> instance I would like to switch auto-fill mode on within comments and
> off everywhere else. It would also be useful for doing things like
> SQLJ, so that you could enable SQL specific functions when within the
> embedded SQL. If anyone has any idea's how to do this Id love to
> hear.
--
Joakim Verona
[EMAIL PROTECTED]
http://www.verona.se/~joakimv
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;switch on/off abbrev mode when writing comments
;abbrev-mode is doesn't woork as an indicator if abbrev-mode is active
;in the buffer
(defadvice put-text-property (after comment-advice activate)
(progn
(if (and (eq property 'face)(eq value 'font-lock-comment-face))
(progn
;(message "%s" "writing comment")
(put-text-property start end 'point-entered 'comment-point-entered)
(put-text-property start end 'point-left 'comment-point-left)
(put-text-property start end 'rear-nonsticky 'true)
)
)
))
(defvar comment-previous-abbrev-flag)
(defun comment-point-entered (arg arg1)
;(message "%s %s %s" "point entered comment"
arg arg1)
(setq comment-previous-abbrev-flag abbrev-mode)
;(message "%s %s %s %s"
comment-previous-abbrev-flag abbrev-mode buffer-file-name (current-buffer))
(abbrev-mode -1))
(defun comment-point-left (arg arg1)
;(message "%s %s %s %s" "point left comment"
arg arg1 (current-buffer))
(abbrev-mode 1);(if comment-previous-abbrev-flag 1 -1))
)