emacs-devel
[Top][All Lists]
Advanced

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

Re: defconst in lao.el


From: Luc Teirlinck
Subject: Re: defconst in lao.el
Date: Tue, 16 Nov 2004 21:01:46 -0600 (CST)

Kenichi Handa wrote:

   I used "defconst" for them because they have to be set back
   to nil when lao.el is re-loaded.  They are setup in the
   following (let ...) form to correct values.  If we change
   them to "defvar", they are anyway set to nil in that (let
   ...) form.  And, conceptually, they are "constant".  So I
   think "defconst" is better.

Yes, but I believe that the defconst is misleading.  When I see:

(defconst var value)

I get the impression that VAR is set for ever after to VALUE.

   It's possible that a user provide different initial value
   for this variable in his .emacs.  In that sense, defvar may
   be better.  On the other hand, modifying this value after
   lao.el is loaded doesn't work.  In that sense, it seems that
   defconst is better.

Yes, but the code can be changed so that modifying the value after
lao.el is loaded _does_ work.

What about the following patch?  It avoids the misleading defconst's,
the compiler warnings, and allows the sophisticated user to set
`lao-key-alist' to a different value in his .emacs, even if lao.el is
already loaded.

===File ~/lao-diff==========================================
*** lao.el      01 Sep 2003 16:08:19 -0500      1.8
--- lao.el      16 Nov 2004 20:40:48 -0600      
***************
*** 2,7 ****
--- 2,8 ----
  
  ;; Copyright (C) 1997 Electrotechnical Laboratory, JAPAN.
  ;; Licensed to the Free Software Foundation.
+ ;; Copyright (C) 2004 Free Software Foundation.
  
  ;; Keywords: multilingual, input method, Lao
  
***************
*** 42,48 ****
          (compose-string (quail-lookup-map-and-concat quail-current-key))))
    control-flag)
  
! (defconst lao-key-alist
    '(("!" . "1")
      ("\"" . "=")
      ("#" . "3")
--- 43,52 ----
          (compose-string (quail-lookup-map-and-concat quail-current-key))))
    control-flag)
  
! ;; If you change the value of this variable, be sure to do
! ;; `(lao-initialize-alists)' afterwards.  Otherwise, the related
! ;; alists will not be properly updated.
! (defvar lao-key-alist
    '(("!" . "1")
      ("\"" . "=")
      ("#" . "3")
***************
*** 148,183 ****
      ("\\9" . "໙")
      ))
  
! (defconst lao-consonant-key-alist nil)
! (defconst lao-semivowel-key-alist nil)
! (defconst lao-vowel-key-alist nil)
! (defconst lao-voweltone-key-alist nil)
! (defconst lao-tone-key-alist nil)
! (defconst lao-other-key-alist nil)
! 
! (let ((tail lao-key-alist)
!       elt phonetic-type)
!   (while tail
!     (setq elt (car tail) tail (cdr tail))
!     (if (stringp (cdr elt))
!       (setq phonetic-type (get-char-code-property (aref (cdr elt) 0)
                                                    'phonetic-type))
!       (setq phonetic-type (get-char-code-property (aref (aref (cdr elt) 0) 0)
!                                                 'phonetic-type))
!       (aset (cdr elt) 0 (compose-string (aref (cdr elt) 0))))
!     (cond ((eq phonetic-type 'consonant)
!          (setq lao-consonant-key-alist (cons elt lao-consonant-key-alist)))
!         ((memq phonetic-type '(vowel-upper vowel-lower))
!          (if (stringp (cdr elt))
!              (setq lao-vowel-key-alist (cons elt lao-vowel-key-alist))
!            (setq lao-voweltone-key-alist
!                  (cons elt lao-voweltone-key-alist))))
!         ((eq  phonetic-type 'tone)
!          (setq lao-tone-key-alist (cons elt lao-tone-key-alist)))
!         ((eq phonetic-type 'semivowel-lower)
!          (setq lao-semivowel-key-alist (cons elt lao-semivowel-key-alist)))
!         (t
!          (setq lao-other-key-alist (cons elt lao-other-key-alist))))))
  
  (quail-define-package
   "lao" "Lao" "ລ" t
--- 152,200 ----
      ("\\9" . "໙")
      ))
  
! (defvar lao-consonant-key-alist nil)
! (defvar lao-semivowel-key-alist nil)
! (defvar lao-vowel-key-alist nil)
! (defvar lao-voweltone-key-alist nil)
! (defvar lao-tone-key-alist nil)
! (defvar lao-other-key-alist nil)
! 
! ;;; autoload
! (defun lao-initialize-alists ()
!   "Properly initialize the lao alists.
! If you change `lao-key-alist', you have to call this function to
! make sure that all related lao alists are properly updated."
!   (setq lao-consonant-key-alist nil
!       lao-semivowel-key-alist nil
!       lao-vowel-key-alist nil
!       lao-voweltone-key-alist nil
!       lao-tone-key-alist nil
!       lao-other-key-alist nil)
!   (let ((tail lao-key-alist)
!       elt phonetic-type)
!     (while tail
!       (setq elt (car tail) tail (cdr tail))
!       (if (stringp (cdr elt))
!         (setq phonetic-type (get-char-code-property (aref (cdr elt) 0)
!                                                     'phonetic-type))
!       (setq phonetic-type (get-char-code-property (aref (aref (cdr elt) 0) 0)
                                                    'phonetic-type))
!       (aset (cdr elt) 0 (compose-string (aref (cdr elt) 0))))
!       (cond ((eq phonetic-type 'consonant)
!            (setq lao-consonant-key-alist (cons elt lao-consonant-key-alist)))
!           ((memq phonetic-type '(vowel-upper vowel-lower))
!            (if (stringp (cdr elt))
!                (setq lao-vowel-key-alist (cons elt lao-vowel-key-alist))
!              (setq lao-voweltone-key-alist
!                    (cons elt lao-voweltone-key-alist))))
!           ((eq  phonetic-type 'tone)
!            (setq lao-tone-key-alist (cons elt lao-tone-key-alist)))
!           ((eq phonetic-type 'semivowel-lower)
!            (setq lao-semivowel-key-alist (cons elt lao-semivowel-key-alist)))
!           (t
!            (setq lao-other-key-alist (cons elt lao-other-key-alist)))))))
! 
! (unless (featurep 'lao) (lao-initialize-alists))
  
  (quail-define-package
   "lao" "Lao" "ລ" t
***************
*** 197,201 ****
--- 214,220 ----
      (v-state (lao-vowel-key-alist . t-state))
      (t-state lao-tone-key-alist))))
  
+ (provide 'lao)
+ 
  ;;; arch-tag: 23863a30-a8bf-402c-b7ce-c517a7aa8570
  ;;; lao.el ends here
============================================================




reply via email to

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