unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* saved user abbrevs and system abbrevs
@ 2006-11-29 21:05 Glenn Morris
  2006-11-30 19:48 ` Richard Stallman
  2006-12-01 20:50 ` Stuart D. Herring
  0 siblings, 2 replies; 6+ messages in thread
From: Glenn Morris @ 2006-11-29 21:05 UTC (permalink / raw)



Emacs 22 will introduce the concept of "user" and "system" abbrevs.
Only user abbrevs get saved into the abbrev-file. Reading the abbrev
file (happens at startup now) defines any saved abbrev-tables, and
populates them with the saved user abbrevs.

Most (all?) modes that define (system) abbrevs do it this way:

(defvar foo-abbrev-table
  (define-abbrev-table 'foo-abbrev-table nil)
  (define-abbrev foo-abbrev-table "foo" "foobar" nil 0 t)
  ...)

If foo-abbrev-table is already defined when the mode is loaded, the
system abbrevs don't get added.

The net result of this is that if a user saves an abbrev, when they
restart Emacs and load the appropriate mode, the system abbrevs do not
get defined.


Does anyone see a better fix than changing each mode that defines
abbrevs to use something like this:

(defvar foo-abbrev-table nil)

;; Do not override any user abbrev for "foo".
(unless (abbrev-expansion "foo" foo-abbrev-table)
  (define-abbrev foo-abbrev-table "foo" "foobar" nil 0 t))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: saved user abbrevs and system abbrevs
  2006-11-29 21:05 saved user abbrevs and system abbrevs Glenn Morris
@ 2006-11-30 19:48 ` Richard Stallman
  2006-12-01  2:54   ` Glenn Morris
  2006-12-01 20:50 ` Stuart D. Herring
  1 sibling, 1 reply; 6+ messages in thread
From: Richard Stallman @ 2006-11-30 19:48 UTC (permalink / raw)
  Cc: emacs-devel

    Does anyone see a better fix than changing each mode that defines
    abbrevs to use something like this:

    (defvar foo-abbrev-table nil)

    ;; Do not override any user abbrev for "foo".
    (unless (abbrev-expansion "foo" foo-abbrev-table)
      (define-abbrev foo-abbrev-table "foo" "foobar" nil 0 t))

Maybe we should change define-abbrev so that defining a system
abbrev does not override any user abbrev (unless you specify
"override") in some way.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: saved user abbrevs and system abbrevs
  2006-11-30 19:48 ` Richard Stallman
@ 2006-12-01  2:54   ` Glenn Morris
  2006-12-01 22:02     ` Richard Stallman
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Morris @ 2006-12-01  2:54 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman wrote:

>     (defvar foo-abbrev-table nil)
>
>     ;; Do not override any user abbrev for "foo".
>     (unless (abbrev-expansion "foo" foo-abbrev-table)
>       (define-abbrev foo-abbrev-table "foo" "foobar" nil 0 t))
>
> Maybe we should change define-abbrev so that defining a system
> abbrev does not override any user abbrev (unless you specify
> "override") in some way.

OK. I was really wondering if there was some way to avoid the problem
of not being able to initialize an abbrev-table in its defvar, since
it seems a bit odd/annoying/hard to remember. But I guess that there
isn't really, and that it does not matter that much.

Here's a patch for your suggestion.

*** abbrev.c   18 Apr 2006 20:57:56 -0000 1.69
--- abbrev.c   1 Dec 2006 02:47:52 -0000
***************
*** 83,89 ****
  
  Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook;
  
! Lisp_Object Qsystem_type, Qcount;
  
  DEFUN ("make-abbrev-table", Fmake_abbrev_table, Smake_abbrev_table,
  0, 0, 0,
         doc: /* Create a new, empty abbrev table object.  */)
--- 83,89 ----
  
  Lisp_Object Vpre_abbrev_expand_hook, Qpre_abbrev_expand_hook;
  
! Lisp_Object Qsystem_type, Qcount, Qforce;
  
  DEFUN ("make-abbrev-table", Fmake_abbrev_table, Smake_abbrev_table,
  0, 0, 0,
         doc: /* Create a new, empty abbrev table object.  */)
***************
*** 123,129 ****
  \(The default is zero.)
  
  SYSTEM-FLAG, if non-nil, says that this is a "system" abbreviation
! which should not be saved in the user's abbreviation file.  */)
       (table, name, expansion, hook, count, system_flag)
       Lisp_Object table, name, expansion, hook, count, system_flag;
  {
--- 123,131 ----
  \(The default is zero.)
  
  SYSTEM-FLAG, if non-nil, says that this is a "system" abbreviation
! which should not be saved in the user's abbreviation file.
! Unless SYSTEM-FLAG is `force', a system abbreviation will not
! overwrite a non-system abbreviation of the same name.  */)
       (table, name, expansion, hook, count, system_flag)
       Lisp_Object table, name, expansion, hook, count, system_flag;
  {
***************
*** 131,136 ****
--- 133,148 ----
    CHECK_VECTOR (table);
    CHECK_STRING (name);
  
+   /* If defining a system abbrev, do not overwrite a non-system abbrev
+      of the same name, unless 'force is used. */
+   if (!NILP (system_flag) && !EQ (system_flag, Qforce))
+     {
+       sym = Fintern_soft (name, table);
+ 
+       if (!NILP (SYMBOL_VALUE (sym)) &&
+           NILP (Fplist_get (XSYMBOL (sym)->plist, Qsystem_type))) return Qnil;
+     }
+ 
    if (NILP (count))
      count = make_number (0);
    else
***************
*** 640,645 ****
--- 652,660 ----
    Qcount = intern ("count");
    staticpro (&Qcount);
  
+   Qforce = intern ("force");
+   staticpro (&Qforce);
+ 
    DEFVAR_LISP ("abbrev-table-name-list", &Vabbrev_table_name_list,
           doc: /* List of symbols whose values are abbrev tables.
           */);
    Vabbrev_table_name_list = Fcons (intern
           ("fundamental-mode-abbrev-table"),

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: saved user abbrevs and system abbrevs
  2006-11-29 21:05 saved user abbrevs and system abbrevs Glenn Morris
  2006-11-30 19:48 ` Richard Stallman
@ 2006-12-01 20:50 ` Stuart D. Herring
  2006-12-02  0:04   ` Glenn Morris
  1 sibling, 1 reply; 6+ messages in thread
From: Stuart D. Herring @ 2006-12-01 20:50 UTC (permalink / raw)
  Cc: emacs-devel

> Does anyone see a better fix than changing each mode that defines
> abbrevs to use something like this:
>
> (defvar foo-abbrev-table nil)
>
> ;; Do not override any user abbrev for "foo".
> (unless (abbrev-expansion "foo" foo-abbrev-table)
>   (define-abbrev foo-abbrev-table "foo" "foobar" nil 0 t))

Well, one thing that would make doing it manually much less painful would
be to implement a trivial function allowing

(populate-abbrev-table 'table-symbol '(("foo" "foobar" nil 0 t) ...))

Alternatively, the system abbrevs could be stored in some other file or
files which major modes would load, similarly to the way that user abbrevs
are already handled:

(load-system-abbrev-table 'my-mode-abbrev-table)

...which would read either an entire file appropriate to the mode, or
perhaps read that part of a master file (lisp/sys.abbrevs or so) that
defined the table in question.

WDOT?
Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: saved user abbrevs and system abbrevs
  2006-12-01  2:54   ` Glenn Morris
@ 2006-12-01 22:02     ` Richard Stallman
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2006-12-01 22:02 UTC (permalink / raw)
  Cc: emacs-devel

If no one finds a problem with this change in 3 days, would you
please install it?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: saved user abbrevs and system abbrevs
  2006-12-01 20:50 ` Stuart D. Herring
@ 2006-12-02  0:04   ` Glenn Morris
  0 siblings, 0 replies; 6+ messages in thread
From: Glenn Morris @ 2006-12-02  0:04 UTC (permalink / raw)
  Cc: emacs-devel

"Stuart D. Herring" wrote:

> Well, one thing that would make doing it manually much less painful
> would be to implement a trivial function allowing
>
> (populate-abbrev-table 'table-symbol '(("foo" "foobar" nil 0 t) ...))

Sure, this is little more than a mapcar, which is how I do it already.

As I said in another mail, I did not explain the issue well the first
time round. What I thought was the main problem is that one cannot
initialize system abbreviations in the defvar for the mode abbrev
table any more (because the abbrev table may already defined before
the mode is loaded, thanks to loading of the user's saved abbrevs).
This seemed like the kind of unexpected behaviour it would be hard to
remember.

In hindsight, I have no idea how I expected anyone to guess that's
what I meant. :)

> Alternatively, the system abbrevs could be stored in some other file
> or files which major modes would load, similarly to the way that
> user abbrevs are already handled:
>
> (load-system-abbrev-table 'my-mode-abbrev-table)

Hmm. I think this is just more work than the current arrangement.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-12-02  0:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-29 21:05 saved user abbrevs and system abbrevs Glenn Morris
2006-11-30 19:48 ` Richard Stallman
2006-12-01  2:54   ` Glenn Morris
2006-12-01 22:02     ` Richard Stallman
2006-12-01 20:50 ` Stuart D. Herring
2006-12-02  0:04   ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).