diff options
| author | Kenichi Handa | 1997-08-28 10:49:48 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1997-08-28 10:49:48 +0000 |
| commit | 70fd2661f63dc5d8c3067e8cd79ca71d7cd817ad (patch) | |
| tree | ef6a36ab3d2a4a18406dc3e4b5621059bb795f30 | |
| parent | ac880bd60a60d73fd1dd672a17ebd7da62ca5d39 (diff) | |
| download | emacs-70fd2661f63dc5d8c3067e8cd79ca71d7cd817ad.tar.gz emacs-70fd2661f63dc5d8c3067e8cd79ca71d7cd817ad.zip | |
(quail-update-leim-list-file): Make it
handle multiple directories.
| -rw-r--r-- | lisp/international/quail.el | 181 |
1 files changed, 107 insertions, 74 deletions
diff --git a/lisp/international/quail.el b/lisp/international/quail.el index 3d1bbbf0452..efffc7dbf43 100644 --- a/lisp/international/quail.el +++ b/lisp/international/quail.el | |||
| @@ -1694,86 +1694,119 @@ key binding | |||
| 1694 | This is a sub-directory of LEIM directory.") | 1694 | This is a sub-directory of LEIM directory.") |
| 1695 | 1695 | ||
| 1696 | ;;;###autoload | 1696 | ;;;###autoload |
| 1697 | (defun quail-update-leim-list-file (dirname) | 1697 | (defun quail-update-leim-list-file (dirname &rest dirnames) |
| 1698 | "Update entries for Quail packages in LEIM list file of directory DIRNAME. | 1698 | "Update entries for Quail packages in `LEIM' list file in directory DIRNAME. |
| 1699 | LEIM is a directory containing Emacs input methods; | 1699 | DIRNAME is a directory containing Emacs input methods; |
| 1700 | normally, it should specify the `leim' subdirectory | 1700 | normally, it should specify the `leim' subdirectory |
| 1701 | of the Emacs source tree." | 1701 | of the Emacs source tree. |
| 1702 | (interactive "FDirectory of LEIM: ") | 1702 | |
| 1703 | (setq dirname (file-name-as-directory (expand-file-name dirname))) | 1703 | It searches for Quail packages under `quail' subdirectory of DIRNAME, |
| 1704 | (let ((quail-dir (concat dirname quail-directory-name)) | 1704 | and update the file \"leim-list.el\" in DIRNAME. |
| 1705 | (filename (concat dirname leim-list-file-name)) | ||
| 1706 | list-buf pkg-list pkg-buf pos) | ||
| 1707 | (if (not (file-exists-p quail-dir)) | ||
| 1708 | nil | ||
| 1709 | (if (not (file-readable-p quail-dir)) | ||
| 1710 | (message "Can't write to file \"%s\"" filename) | ||
| 1711 | (if (not (file-writable-p filename)) | ||
| 1712 | (message "Can't write to file \"%s\"" filename) | ||
| 1713 | (setq list-buf (find-file-noselect filename)) | ||
| 1714 | (setq pkg-list (directory-files quail-dir 'full ".*\\.el$" 'nosort)) | ||
| 1715 | (message "Updating %s ..." filename) | ||
| 1716 | |||
| 1717 | ;; At first, clean up the file. | ||
| 1718 | (save-excursion | ||
| 1719 | (set-buffer list-buf) | ||
| 1720 | (goto-char 1) | ||
| 1721 | |||
| 1722 | ;; Insert the correct header. | ||
| 1723 | (if (looking-at (regexp-quote leim-list-header)) | ||
| 1724 | (goto-char (match-end 0)) | ||
| 1725 | (insert leim-list-header)) | ||
| 1726 | (setq pos (point)) | ||
| 1727 | (if (not (re-search-forward leim-list-entry-regexp nil t)) | ||
| 1728 | nil | ||
| 1729 | 1705 | ||
| 1730 | ;; Remove garbages after the header. | 1706 | When called from a program, the remaining arguments are additional |
| 1707 | directory names to search for Quail packages under `quail' subdirectory | ||
| 1708 | of each directory." | ||
| 1709 | (interactive "FDirectory of LEIM: ") | ||
| 1710 | (setq dirname (expand-file-name dirname)) | ||
| 1711 | (let ((leim-list (expand-file-name leim-list-file-name dirname)) | ||
| 1712 | quail-dirs list-buf pkg-list pkg-buf pos) | ||
| 1713 | (if (not (file-writable-p leim-list)) | ||
| 1714 | (error "Can't write to file \"%s\"" leim-list)) | ||
| 1715 | (message "Updating %s ..." leim-list) | ||
| 1716 | (setq list-buf (find-file-noselect leim-list)) | ||
| 1717 | |||
| 1718 | ;; At first, clean up the file. | ||
| 1719 | (save-excursion | ||
| 1720 | (set-buffer list-buf) | ||
| 1721 | (goto-char 1) | ||
| 1722 | |||
| 1723 | ;; Insert the correct header. | ||
| 1724 | (if (looking-at (regexp-quote leim-list-header)) | ||
| 1725 | (goto-char (match-end 0)) | ||
| 1726 | (insert leim-list-header)) | ||
| 1727 | (setq pos (point)) | ||
| 1728 | (if (not (re-search-forward leim-list-entry-regexp nil t)) | ||
| 1729 | nil | ||
| 1730 | |||
| 1731 | ;; Remove garbages after the header. | ||
| 1732 | (goto-char (match-beginning 0)) | ||
| 1733 | (if (< pos (point)) | ||
| 1734 | (delete-region pos (point))) | ||
| 1735 | |||
| 1736 | ;; Remove all entries for Quail. | ||
| 1737 | (while (re-search-forward leim-list-entry-regexp nil 'move) | ||
| 1738 | (goto-char (match-beginning 0)) | ||
| 1739 | (setq pos (point)) | ||
| 1740 | (condition-case nil | ||
| 1741 | (let ((form (read list-buf))) | ||
| 1742 | (when (equal (nth 3 form) ''quail-use-package) | ||
| 1743 | (if (eolp) (forward-line 1)) | ||
| 1744 | (delete-region pos (point)))) | ||
| 1745 | (error | ||
| 1746 | ;; Delete the remaining contents because it seems that | ||
| 1747 | ;; this file is broken. | ||
| 1748 | (message "Garbages in %s deleted" leim-list) | ||
| 1749 | (delete-region pos (point-max))))))) | ||
| 1750 | |||
| 1751 | ;; Search for `quail' subdirector under each DIRNAMES. | ||
| 1752 | (setq dirnames (cons dirname dirnames)) | ||
| 1753 | (let ((l dirnames)) | ||
| 1754 | (while l | ||
| 1755 | (setcar l (expand-file-name (car l))) | ||
| 1756 | (setq dirname (expand-file-name quail-directory-name (car l))) | ||
| 1757 | (if (file-readable-p dirname) | ||
| 1758 | (setq quail-dirs (cons dirname quail-dirs)) | ||
| 1759 | (message "%s doesn't has `%s' subdirectory, just ignored" | ||
| 1760 | (car l) quail-directory-name) | ||
| 1761 | (setq quail-dirs (cons nil quail-dirs))) | ||
| 1762 | (setq l (cdr l))) | ||
| 1763 | (setq quail-dirs (nreverse quail-dirs))) | ||
| 1764 | |||
| 1765 | ;; Insert input method registering forms. | ||
| 1766 | (while quail-dirs | ||
| 1767 | (setq dirname (car quail-dirs)) | ||
| 1768 | (when dirname | ||
| 1769 | (setq pkg-list (directory-files dirname 'full "\\.el$" 'nosort)) | ||
| 1770 | (while pkg-list | ||
| 1771 | (message "Checking %s ..." (car pkg-list)) | ||
| 1772 | (with-temp-buffer | ||
| 1773 | (insert-file-contents (car pkg-list)) | ||
| 1774 | (goto-char (point-min)) | ||
| 1775 | (while (search-forward "(quail-define-package" nil t) | ||
| 1731 | (goto-char (match-beginning 0)) | 1776 | (goto-char (match-beginning 0)) |
| 1732 | (if (< pos (point)) | 1777 | (condition-case nil |
| 1733 | (delete-region pos (point))) | 1778 | (let ((form (read (current-buffer)))) |
| 1734 | 1779 | (save-excursion | |
| 1735 | ;; Remove all entries for Quail. | 1780 | (set-buffer list-buf) |
| 1736 | (while (re-search-forward leim-list-entry-regexp nil 'move) | 1781 | (insert |
| 1737 | (goto-char (match-beginning 0)) | 1782 | (format "(register-input-method |
| 1738 | (setq pos (point)) | ||
| 1739 | (let ((form (read list-buf))) | ||
| 1740 | (if (equal (nth 3 form) ''quail-use-package) | ||
| 1741 | (progn | ||
| 1742 | (if (eolp) (forward-line 1)) | ||
| 1743 | (delete-region pos (point)))))))) | ||
| 1744 | |||
| 1745 | ;; Insert entries for Quail. | ||
| 1746 | (while pkg-list | ||
| 1747 | (message "Checking %s ..." (car pkg-list)) | ||
| 1748 | (with-temp-buffer | ||
| 1749 | (insert-file-contents (car pkg-list)) | ||
| 1750 | (goto-char (point-min)) | ||
| 1751 | (while (search-forward "(quail-define-package" nil t) | ||
| 1752 | (goto-char (match-beginning 0)) | ||
| 1753 | (let ((form (read (current-buffer)))) | ||
| 1754 | (save-excursion | ||
| 1755 | (set-buffer list-buf) | ||
| 1756 | (insert (format "(register-input-method | ||
| 1757 | %S %S '%s | 1783 | %S %S '%s |
| 1758 | %S %S | 1784 | %S %S |
| 1759 | %S)\n" | 1785 | %S)\n" |
| 1760 | (nth 1 form) ; PACKAGE-NAME | 1786 | (nth 1 form) ; PACKAGE-NAME |
| 1761 | (nth 2 form) ; LANGUAGE | 1787 | (nth 2 form) ; LANGUAGE |
| 1762 | 'quail-use-package ; ACTIVATE-FUNC | 1788 | 'quail-use-package ; ACTIVATE-FUNC |
| 1763 | (nth 3 form) ; PACKAGE-TITLE | 1789 | (nth 3 form) ; PACKAGE-TITLE |
| 1764 | (progn ; PACKAGE-DESCRIPTION (one line) | 1790 | (progn ; PACKAGE-DESCRIPTION (one line) |
| 1765 | (string-match ".*" (nth 5 form)) | 1791 | (string-match ".*" (nth 5 form)) |
| 1766 | (match-string 0 (nth 5 form))) | 1792 | (match-string 0 (nth 5 form))) |
| 1767 | (file-relative-name ; PACKAGE-FILENAME | 1793 | (file-relative-name ; PACKAGE-FILENAME |
| 1768 | (file-name-sans-extension (car pkg-list)) | 1794 | (file-name-sans-extension (car pkg-list)) |
| 1769 | dirname))))))) | 1795 | (car dirnames)))))) |
| 1770 | (setq pkg-list (cdr pkg-list))) | 1796 | (error |
| 1771 | (save-excursion | 1797 | ;; Ignore the remaining contents of this file. |
| 1772 | (set-buffer list-buf) | 1798 | (goto-char (point-max)) |
| 1773 | (setq buffer-file-coding-system 'iso-2022-7bit) | 1799 | (message "Some part of \"%s\" is broken" dirname))))) |
| 1774 | (save-buffer 0)) | 1800 | (setq pkg-list (cdr pkg-list))) |
| 1775 | (kill-buffer list-buf) | 1801 | (setq quail-dirs (cdr quail-dirs) dirnames (cdr dirnames)))) |
| 1776 | (message "Updating %s ... done" (buffer-file-name list-buf))))))) | 1802 | |
| 1803 | ;; At last, write out LEIM list file. | ||
| 1804 | (save-excursion | ||
| 1805 | (set-buffer list-buf) | ||
| 1806 | (setq buffer-file-coding-system 'iso-2022-7bit) | ||
| 1807 | (save-buffer 0)) | ||
| 1808 | (kill-buffer list-buf) | ||
| 1809 | (message "Updating %s ... done" leim-list))) | ||
| 1777 | ;; | 1810 | ;; |
| 1778 | (provide 'quail) | 1811 | (provide 'quail) |
| 1779 | 1812 | ||