emacs-devel
[Top][All Lists]
Advanced

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

Re: smartquotes.el -- Insertion of unicode quotes in text documents


From: Kenichi Handa
Subject: Re: smartquotes.el -- Insertion of unicode quotes in text documents
Date: Tue, 04 Sep 2007 15:48:38 +0900
User-agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/23.0.0 (i686-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

In article <address@hidden>, Richard Stallman <address@hidden> writes:

>     What kind of user interface should be provided for
>     activating and deactivating multiple input methods?

> Here's one idea: the user enables and disables one input method,
> directly, and the others are enabled or disabled by a Lisp interface.
> That Lisp interface can be called by other commands.

> Does this solve that one problem?

Yes.  I implemented it as an add-on code (with a little bit
tricky way).  Once it is found that it works well, I'll
merge the code into mule-cmds.el while cleaning the code.

Please try the attached code with the latest
emacs-unicode-2.  The Lisp interfaces are the functions
activate-preposition-input-method and
inactivate-preposition-input-method.

---
Kenichi Handa
address@hidden

(defvar local-input-method-list nil
  "List of local preposition input methods.")
(make-variable-buffer-local 'local-input-method-list)
(defvar global-input-method-list nil
  "List of global preposition input methods.")
(defvar normal-input-method nil
  "Currently active normal (i.e. non-preposion) input method.")

(defun multi-input-method-function (event)
  "Input method function used while some preposition input method is active."
  (let ((disable-input-method-hook t)
        unread-command-events)
    (dolist (elt (append global-input-method-list
                         local-input-method-list))
      (let (input-method-history default-input-method)
        (activate-input-method elt)
        (setq unread-command-events
              (nreverse (funcall input-method-function event)))
        (setq event (car unread-command-events)
              unread-command-events (cdr unread-command-events))))
    (let (input-method-history)
      (inactivate-input-method))
    (setq current-input-method nil
          current-input-method-title nil)
    (unwind-protect
        (if normal-input-method
            (progn
              (activate-input-method normal-input-method)
              (append (funcall input-method-function event)
                      unread-command-events))
          (cons event unread-command-events))
      (setq input-method-function 'multi-input-method-function))))

;; If non-nil, disable input-method-hook.
(defvar disable-input-method-hook nil)

;; A function for input-method-active-hook used while some preposition
;; input method is active.
(defun input-method-activate-hook ()
  (unless disable-input-method-hook
    (setq normal-input-method current-input-method)
    (if (or local-input-method-list global-input-method-list)
        (setq input-method-function 'multi-input-method-function))))
              
;; A function for input-method-inactivate-hook used while some
;; preposition input method is active.
(defun input-method-inactivate-hook ()
  (unless disable-input-method-hook
    (setq normal-input-method nil)
    (if (or local-input-method-list global-input-method-list)
        (setq input-method-function 'multi-input-method-function))))

(defun activate-preposition-input-method (input-method global)
  "Activate a preposition INPUT-METHOD.
INPUT-METHOD is handled before a normal input method.
If the second arg GLOBAL is non-nil, activate it for all buffers.
Otherwise, activate it only for the current buffer."
  (if (and input-method (symbolp input-method))
      (setq input-method (symbol-name input-method)))
  (or (assoc input-method input-method-alist)
      (error "Unknown input method: %s" input-method))
  (unless (assoc-string input-method 
                        (if global global-input-method-list
                          local-input-method-list))
    (or global-input-method-list
        local-input-method-list
        (progn
          (add-hook 'input-method-activate-hook
                    'input-method-activate-hook)
          (add-hook 'input-method-inactivate-hook
                    'input-method-inactivate-hook)))
    (setq normal-input-method current-input-method)
    (if global
        (progn
          (push input-method global-input-method-list)
          (setq-default input-method-function 'multi-input-method-function))
      (push input-method local-input-method-list))
    (make-local-variable 'input-method-function)
    (setq input-method-function 'multi-input-method-function)))

(defun inactivate-preposition-input-method (input-method global)
  "Inactivate a proposition INPUT-METHOD.
If the second arg GLOBAL is non-nil, inactivate it for all buffers.
Otherwise, inactivate it only for the curren buffer."
  (if (and input-method (symbolp input-method))
      (setq input-method (symbol-name input-method)))
  (if global
      (setq global-input-method-list
            (delete input-method global-input-method-list))
    (setq local-input-method-list
          (delete input-method local-input-method-list)))
  (or global-input-method-list
      local-input-method-list
      (progn
        (remove-hook 'input-method-activate-hook
                     'input-method-activate-hook)
        (remove-hook 'input-method-inactivate-hook
                     'input-method-inactivate-hook)
        (setq input-method-function nil)
        (when normal-input-method
          (inactivate-input-method)
          (activate-input-method normal-input-method)))))




reply via email to

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