From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Kanis Newsgroups: gmane.emacs.devel Subject: Re: Is there a way to create an input method based on another one? Date: Wed, 27 Feb 2013 19:51:17 +0100 Message-ID: <87wqttd1zu.fsf@kanis.fr> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1361991123 21144 80.91.229.3 (27 Feb 2013 18:52:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Feb 2013 18:52:03 +0000 (UTC) Cc: Emacs Developers To: Nikolai Weibull Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 27 19:52:26 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UAm77-0005CM-7k for ged-emacs-devel@m.gmane.org; Wed, 27 Feb 2013 19:52:25 +0100 Original-Received: from localhost ([::1]:49447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAm6j-0004qE-3w for ged-emacs-devel@m.gmane.org; Wed, 27 Feb 2013 13:52:01 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:46469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAm6W-0004mg-QP for emacs-devel@gnu.org; Wed, 27 Feb 2013 13:51:56 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAm6J-0003Gl-6v for emacs-devel@gnu.org; Wed, 27 Feb 2013 13:51:43 -0500 Original-Received: from smtp.kanis.fr ([164.138.25.8]:49444 helo=kanis.fr) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAm6H-0003CS-MG for emacs-devel@gnu.org; Wed, 27 Feb 2013 13:51:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=comencini.fr; s=alpha; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References:Subject:Cc:To:From; bh=aPYX+ztXUxJQpU0MfPTfA5P0MayCLia/rtLnG+l7mjw=; b=CRaudVT4Y/SrD2Njy0Y6HYCfHyYfCi9wqCO1juiiP/JKJUFtlkTm3M36zIn3ceKQFOhQip9eJv6mf55N2luBOhqgpMlriGGEeZEno8DbYba+dOtFER16k9qtzHGdukei; Original-Received: from smtp.comencini.fr ([164.138.25.8]) by smtp.comencini.fr with esmtpsa (TLS1.1:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80.1) (envelope-from ) id 1UAm63-0000MQ-Pk; Wed, 27 Feb 2013 19:51:21 +0100 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAAB5QTFRF IBkXUxMTOCwoTC4qcUY8iFxQmmper31txpaJ/v/8aKZ1oAAAAcVJREFUOMt100tu2zAQAFDCXnUZ oAcIqG68LZULVLQBbwuSiffm6AIRRyeotAySJoVu2+FPpJWWC3/4NKOZocSW/yxWfnJ2+Bdwzhj7 8gleWVy7DXC2rkMNr2V/zRbghXIwthf3VbIA9Ffc71vZCSFyCEsBggtNS8ludwvfmhYA0Vn9o4DP zMWxR7+cPWzAYFzwM0ModtdmcDbDS6i/hT7L+RZof5yCXGrYe5jn2YO6BYMjgY+51tCIAqHgBLwR pwLnGuRjAKyBJkuN4yd4U92uCY1vUr2D/c5b8DuxyQwfOHUeaLqDJhnkkuGXbB56h2C1IVBdgncc bBi6feroa9B6jUDojnQPQKupbyXyeeCE1oT7Oqrt+SnfY3mkiyGA/3AmD3H5g32CcBx6hY8pRkwJ 9PpcjRGobUfprFnhAa1vepwcgMOhwG+pdSgKHFU9HAvoAH6XUl7lDUCCq5Qb6GMbVm3Aj++qDYCt wdBc/YHgOFCmS3mjDMRcSE2qY4E3Q3PVIQRQmeodNH4QEbRUFZzW+VotzwX4yTcRTySOML1qjcE5 hTirVqDHkMAP0PjAywp3d18JZtqzvr9zDYD+GaSKtE6Zlr/DLPNFmOcvBAAAAABJRU5ErkJggg== X-Hashcash: 1:20:130227:emacs-devel@gnu.org::bw6Duon0U0szCBaK:0000000000000000000000000000000000000000001H9o X-Hashcash: 1:20:130227:now@bitwi.se::63lMX5gRbyAoarHn:000002YMm In-Reply-To: (Nikolai Weibull's message of "Wed, 27 Feb 2013 16:01:09 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 164.138.25.8 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:157440 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable February, 27 at 16:01 Nikolai Weibull wrote: > existing one (rfc1345). As far as I can tell from reading the source, > the =E2=80=9Cpublic=E2=80=9D (undocumented) API seems to be quail-define-= package > followed by quail-define-rules, which seems to be unable to > accommodate my desires. > > Am I missing something? No you're not missing anything. I have attached my french input source code that you may find handy. The entry point is ivan-french-keymap-load. Take care, --=20 Your packets were eaten by the terminator. -- BOFH excuse #20 --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=ivan-french.el Content-Transfer-Encoding: quoted-printable ;;; ivan-french.el --- french functions (require 'ivan-keymap) (eval-when-compile (require 'cl)) (defvar ivan-french-dictionary-name "french" "String specifying the french dictionary") (defvar ivan-french-keymap-load nil) (defvar ivan-french-strip-alist (let ((with-accent "=C3=80=C3=81=C3=82=C3=83=C3=84=C3=85=C3=87=C3=88=C3=89=C3=8A=C3= =8B=C3=8C=C3=8D=C3=8E=C3=8F=C3=90=C3=91=C3=92=C3=93=C3=94=C3=95=C3=96=C3=98= =C3=99=C3=9A=C3=9B=C3=9C=C3=9D=C3=9F=C3=A0=C3=A1=C3=A2=C3=A3=C3=A4=C3=A5=C3= =A7=C3=A8=C3=A9=C3=AA=C3=AB=C3=AC=C3=AD=C3=AE=C3=AF=C3=B1=C3=B2=C3=B3=C3=B4= =C3=B5=C3=B6=C3=B8=C3=B9=C3=BA=C3=BB=C3=BC=C3=BD=C3=BF") (without-accent "AAAAAACEEEEIIIIDNOOOOOOUUUUYBaaaaaaceeeeiiiinoooooouuuuyy") (index 0) alist) (while (< index (length with-accent)) (add-to-list 'alist (cons (aref with-accent index) (aref without-accent index))) (incf index)) alist) "Alist of accented characters with their ASCII reprensation.") (defun ivan-french-strip-accent (string) "Strip accents from STRING." (concat (mapcar (lambda (el) (let ((letter (assoc el ivan-french-strip-alist))) (if letter (cdr letter) el))) (append string nil)))) (defun ivan-french-dictionary () (interactive) (require 'w3m) (w3m (concat "http://atilf.atilf.fr/dendien/scripts/fast.exe?mot=3D" (w3m-url-encode-string (read-string "French dictionary: " (current-word) 'ivan-french-dictionary-history (current-word)))))) (defun ivan-french-flyspell () (interactive) (ivan-french-input) (ivan-french-set-dictionary) (flyspell-mode 1)) (defun ivan-french-set-dictionary () "Set french dictionary for spelling" (ivan-fun-spell ivan-french-dictionary-name 'set)) (defun ivan-french-input () (interactive) (ivan-french-keymap-load) (activate-input-method 'ivan-french-prefix) (ivan-french-mode 1)) (defun ivan-french-spell () (interactive) (ivan-fun-spell ivan-french-dictionary-name)) (defun ivan-french-spell-region () (interactive) (ivan-fun-spell ivan-french-dictionary-name 'region)) (defun ivan-french-spell-word () (interactive) (ivan-fun-spell ivan-french-dictionary-name 'word)) (defun ivan-french-letter () (interactive) (setq ivan-var-letter-english nil) (ivan-fun-letter) (ivan-fun-spell ivan-french-dictionary-name 'set) (flyspell-mode 1)) (defun ivan-french-message () (interactive) "Setup french when composing a message" (setq ivan-var-reply-lang "french") (if (string=3D var-init-user "ivan") (ivan-french-input)) (ivan-fun-spell ivan-french-dictionary-name 'set) (ivan-message-replace)) (defun ivan-french-quotes () "Match =C2=AB and =C2=BB with context in a paragraph." (interactive) (let* ((bgn-paragraph (save-excursion (forward-paragraph -1) (point))) (quote (save-excursion (re-search-backward "=C2=AB\\|=C2=BB" bgn-paragraph t) (match-string 0)))) (insert (if (and (stringp quote) (string=3D "=C2=AB" quote)) "=C2=A0=C2=BB" "=C2=AB=C2= =A0")))) (defmacro ivan-french-insert-space (symbol char) "Define function that will insert non breaking space for french character such as the question mark. It will delete a normal space if it exists. This useful after expanding an abbreviation." `(defun ,(intern (concat "ivan-french-" symbol)) () (interactive) (if (ivan-french-insert-space-ok) (progn (let* ((point (point)) (end (if (> point 0) (- point 1)))) (if (re-search-backward " " end t) (delete-char 1))) (insert ,(concat "=C2=A0" char))) (insert ,char)))) (defun ivan-french-insert-space-ok () "Return t when it's OK to insert non breaking space. Places to avoid are the ERC prompt, e-mail headers and the timestamp in org mode." (not (or (ivan-french-match '("ERC> " "cc" "to" "bcc")) (ivan-french-in-timestamp)))) (defun ivan-french-match (list) "Return t if text preceding the cursor matches LIST." (let ((point (point)) (ret nil)) (while list (let* ((string (car list)) (length (length string)) (start (- point length))) (and (> point length) (=3D start (line-beginning-position)) (string=3D (buffer-substring start point) string) (setq ret t list nil)) (setq list (cdr list)))) ret)) (defun ivan-french-in-timestamp () "See if cursor is in an org style timestamp." (let ((line-number (line-number-at-pos)) (line-previous (ivan-french-in-timestamp-ex -1)) (line-next (ivan-french-in-timestamp-ex 1))) (and line-previous (=3D line-previous line-number) line-next (=3D line-next line-number)))) (defun ivan-french-in-timestamp-ex (way) "Return line position of timestamp character." (save-excursion (when (if (> way 0) (search-forward ">" nil t) (search-backward "<" nil t)) (line-number-at-pos)))) (ivan-french-insert-space "question" "?") (ivan-french-insert-space "exclamation" "!") (ivan-french-insert-space "colon" ":") (ivan-french-insert-space "semicolon" ";") (define-minor-mode ivan-french-mode "Toggle french mode in the current buffer." :keymap '(("\"" . ivan-french-quotes) ("?" . ivan-french-question) ("!" . ivan-french-exclamation) (":" . ivan-french-colon) (";" . ivan-french-semicolon))) (defun ivan-french-keymap-load () "Initialize french keymap." (when (not ivan-french-keymap-load) (require 'quail) (setq ivan-french-keymap-load t) (quail-define-package "ivan-french-prefix" "Latin-9" "F>" t "French characters input method with prefix modifiers effect | prefix | examples ------------+--------+---------- acute | ' | 'e -> =C3=A9 'c -> =C3=A7 grave | ` | `a -> =C3=A0 circumflex | ^ | ^a -> =C3=A2 ^1 -> =C2=B9 ^c -> =C2=A9 tilde | ~ | ~a -> =C3=A6 ~o -> =C5=93 ~c -> tilde | ~ | ~> -> =C2=BB ~< -> =C2=AB underscore | _ | _/ -> =C3=B7 _e -> =E2=82=AC " nil t nil nil nil nil nil nil nil nil t) (quail-define-rules ("' " ?') ("'C" ?=C3=87) ("'E" ?=C3=89) ("'c" ?=C3=A7) ("'e" ?=C3=A9) ("\" " ?\") ("\"A" ?=C3=84) ("\"E" ?=C3=8B) ("\"a" ?=C3=A4) ("\"e" ?=C3=AB) ("\"i" ?=C3=AF) ("^ " ?^) ("^1" ?=C2=B9) ("^2" ?=C2=B2) ("^3" ?=C2=B3) ("^A" ?=C3=82) ("^E" ?=C3=8A) ("^I" ?=C3=8E) ("^O" ?=C3=94) ("^U" ?=C3=9B) ("^^" ?^) ("^a" ?=C3=A2) ("^c" ?=C2=A9) ("^e" ?=C3=AA) ("^i" ?=C3=AE) ("^o" ?=C3=B4) ("^r" ?=C2=AE) ("^u" ?=C3=BB) ("_ " ?=C2=A0) ("_/" ?=C3=B7) ("__" ?_) ("_c" ?=C2=A2) ("_e" ?=E2=82=AC) ("_o" ?=C2=BA) ("_p" ?=C2=A3) ("_y" ?=C2=A5) ("` " ?`) ("`A" ?=C3=80) ("`E" ?=C3=88) ("`U" ?=C3=99) ("``" ?`) ("`a" ?=C3=A0) ("`e" ?=C3=A8) ("`u" ?=C3=B9) ("~ " ?~) ("~<" ?\=C2=AB) ("~>" ?\=C2=BB) ("~A" ?=C3=86) ("~O" ?=C5=92) ("~a" ?=C3=A6) ("~c" ?=C2=B0) ("~o" ?=C5=93)))) (ivan-keymap-prefix ivan-keymap-french-map "c" verbiste "d" ivan-french-dictionary "f" ivan-french-flyspell "i" ivan-french-input "l" ivan-french-letter "m" ivan-french-message "p" ivan-french-motivation "r" ivan-french-spell-region "s" ivan-french-spell "w" ivan-french-spell-word) (provide 'ivan-french) ;; Copyright (C) 2007 Ivan Kanis ;; Author: Ivan Kanis ;; ;; ;; 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 of the License, 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 ; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --=-=-=--