On Thu, Apr 27, 2000 at 01:07:03AM +0000, Paul Kinnucan wrote:
> At 02:43 PM 4/26/00 +0100, you wrote:
>
> >Hi,
> >
> >Is it by any chance possible to turn off or override the use of
> >abbreviations when adding text in comments? I find that having words
> >in comments extended more often than not is just annoying.
>
>
> M-x abbrev-mode toggles use of abbreviations. You could bind this to a
> key.
This was emailed quite a while ago by Phillip Lord but works great for
me just stick it in your load path and add (require 'jde-auto-abbrev)
after you load jde in your .emacs . He said it works great using NTEmacs
and I can confirm that it works under Xemacs for solaris. I can't
remember if I modified his version so here is the copy I use.
By the way I noticed that it works much faster if you byte compile it.
--
;; jde-auto-abbrev.el - quick and dirty folding package for emacs
;; $Revision: 1.2 $
;; $Date: 1999-12-10 00:13:59+00 $
;; This file is not part of Emacs
;; Nor is it part of the JDE.
;; It is an add-on to both of them however!
;; Author: Phillip Lord<[EMAIL PROTECTED]>
;; Maintainer: Phillip Lord
;; Keywords: java, tools, abbreviations, filling
;; Copyright (c) 1999 Phillip Lord
;; COPYRIGHT NOTICE
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;;
;; Status
;;
;; This seems to work okay at the moment, and I use it regularly. It
;; should however be considered to be beta software until other people
;; have used it a little more. Please note that this means if you use
;; it for a while and it works, then bloody well tell me about it!!!!
;;
;; This kind of behviour would be pretty useful in other modes as
;; well. I use a similiar thing in lisp mode also (to turn filling
;; only on and off). If people think that this would be useful for
;; many other modes, then let me know and I will think about
;; re-writing this much more generically so that it is not tied to
;; JDE.
;;
;; The software was designed, written and tested on win 95, using
;; NTEmacs and JDE2.1.5, and a 2.1.6 beta reliease. Please let
;; me know if it works elsewhere. The current version should
;; be available at http://genetics.ich.ucl.ac.uk/plord
;;;
;; Installation
;;
;; Place this file into your load path.
;; Stick this in your .emacs
;;
;; (require 'jde-auto-abbrev)
;;
;; and thats it. Although you might want to install fill-adapt as
;; well.
;;;
;; Usage
;;
;; This file switches abbreviation mode on and off depending on
;; whether point in an comment, or a string or not. As the jde
;; abbreviations relate to programming you want to switch things off
;; in comments!
;;
;; It also does the same thing for auto-fill-mode. This makes the name
;; a little inappropriate, but the name would get too long
;; otherwise. I use the fill-adapt package, and emacs itself comes
;; with adaptive fill these days so comments should be filled
;; properly, although I have found for a // comment mark to be
;; identified as a prefix there has to be a space between the // and
;; the comment!
;;
;; There are four commands called
;;
;; jde-auto-abbrev-disable-local
;; jde-auto-abbrev-enable-local
;; jde-auto-abbrev-disable
;; jde-auto-abbrev-enable
;;
;; which you might want to use occasionally.
;;;
;; Bugs and Limitations
;;
;; 1) I sometimes use abbreviations in comments which I cant do with
;; this, altough expand-abbrev would work. It would be nice to switch
;; in and out one set of abbrevs for comments and one for program text
;;;
;; Acknowledgements.
;;
;; I had the idea for this a while back, and posted a request on the
;; JDE mailing list. Joakim Verona ([EMAIL PROTECTED]) sent me his
;; solution to the problem. He used defadvice on "put-text-property",
;; which actually worked pretty well, but produced occasional errors,
;; and was sometimes slow in changing. I eventually got the idea of
;; using post-command-hook from Gerd Neugebauer multi-mode.el. Emacs
;; has hooks for everything of course, but it had still not occured to
;; me to look for this one. Shows the value of picking around randomly
;; through other peoples code (and of course the value of free
;; software!). Thanks to both of these people.
(defun jde-auto-abbrev-install-in-buffer()
(make-local-hook 'post-command-hook)
(add-hook 'post-command-hook 'jde-auto-abbrev-post-command-hook)
(make-local-variable 'jde-auto-abbrev-comment-p)
(make-local-variable 'jde-auto-abbrev-string-p))
(defun jde-auto-abbrev-post-command-hook()
(interactive)
(if (not jde-auto-abbrev-disable-p)
(let ((face-at-point (get-text-property (point) 'face)))
;; the text property can be single or a list. So if its a
;; list, doesnt it contain the appropriate face?, or it its
;; not a list is it equal to the appropriate face
;; first we check for comments
(if (or
(and (listp face-at-point)
(memq 'font-lock-comment-face face-at-point))
(eq face-at-point 'font-lock-comment-face))
(jde-auto-abbrev-on-comment)
(jde-auto-abbrev-off-comment))
;; then we check for strings
(if
(or
(and (listp face-at-point)
(memq 'font-lock-string-face face-at-point))
(eq face-at-point 'font-lock-string-face))
(jde-auto-abbrev-on-string)
(jde-auto-abbrev-off-string)))))
(defvar jde-auto-abbrev-comment-p)
(setq-default jde-auto-abbrev-comment-p nil)
(defun jde-auto-abbrev-on-comment()
;;turn on auto-fill if on a comment, if we previously were not on a
;;comment.
(if (not jde-auto-abbrev-comment-p)
(progn
(setq jde-auto-abbrev-comment-p t)
(jde-auto-abbrev-default))))
(defun jde-auto-abbrev-off-comment()
;;turn off auto-fill if no on a comment
(if jde-auto-abbrev-comment-p
(progn
(setq jde-auto-abbrev-comment-p nil)
;;on abbrev, on auto fill
(abbrev-mode 1)
(auto-fill-mode 0))))
(defvar jde-auto-abbrev-string-p)
(setq-default jde-auto-abbrev-string-p nil)
(defun jde-auto-abbrev-on-string()
(if (not jde-auto-abbrev-string-p)
(progn
(setq jde-auto-abbrev-string-p t)
;;off auto fill, off abbrev
(abbrev-mode -1)
(auto-fill-mode 0))))
(defun jde-auto-abbrev-off-string()
(if jde-auto-abbrev-string-p
(progn
(setq jde-auto-abbrev-string-p nil)
(abbrev-mode 1)
(auto-fill-mode 0))))
;(jde-auto-abbrev-default))))
(defun jde-auto-abbrev-default()
;;on comment swith off abbrev, and on auto fill
(abbrev-mode -1)
(auto-fill-mode 1))
(add-hook 'jde-mode-hook 'jde-auto-abbrev-install-in-buffer)
(defun jde-auto-abbrev-disable-local()
(interactive)
(remove-hook 'post-command-hook))
(defun jde-auto-abbrev-enable-local()
(interactive)
(jde-auto-abbrev-install-in-buffer))
(defvar jde-auto-abbrev-disable-p nil)
(defun jde-auto-abbrev-disable()
(interactive)
(setq jde-auto-abbrev-disable-p t))
(defun jde-auto-abbrev-enable()
(interactive)
(setq jde-auto-abbrev-enable-p nil))
(provide 'jde-auto-abbrev)
;;
;; $Log: jde-auto-abbrev.el,v $
;; Revision 1.2 1999-12-10 00:13:59+00 phillip2
;; FIxed bug where font-lock has proscribed more than one property within a
;; comment, or a string.
;;
;; Revision 1.1 1999-12-09 18:59:42+00 phillip2
;; Initial revision
;;
;;