Mercurial > emacs
comparison lisp/term/mac-win.el @ 90428:a8190f7e546e
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 285-296)
- Update from CVS
- Merge from gnus--rel--5.10
- Update from CVS: admin/FOR-RELEASE: Update refcard section.
* gnus--rel--5.10 (patch 102-104)
- Update from CVS
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-64
author | Miles Bader <miles@gnu.org> |
---|---|
date | Wed, 07 Jun 2006 18:05:10 +0000 |
parents | 914bfaec949a ed68e074ebb4 |
children | 138027c8c982 |
comparison
equal
deleted
inserted
replaced
90427:ddb25860d044 | 90428:a8190f7e546e |
---|---|
82 (defvar mac-service-selection) | 82 (defvar mac-service-selection) |
83 (defvar mac-system-script-code) | 83 (defvar mac-system-script-code) |
84 (defvar mac-apple-event-map) | 84 (defvar mac-apple-event-map) |
85 (defvar mac-atsu-font-table) | 85 (defvar mac-atsu-font-table) |
86 (defvar mac-font-panel-mode) | 86 (defvar mac-font-panel-mode) |
87 (defvar mac-ts-active-input-overlay) | |
87 (defvar x-invocation-args) | 88 (defvar x-invocation-args) |
88 | 89 |
89 (defvar x-command-line-resources nil) | 90 (defvar x-command-line-resources nil) |
90 | 91 |
91 ;; Handler for switches of the form "-switch value" or "-switch". | 92 ;; Handler for switches of the form "-switch value" or "-switch". |
1618 (mapcar | 1619 (mapcar |
1619 (lambda (type-data) | 1620 (lambda (type-data) |
1620 (mac-coerce-ae-data (car type-data) (cdr type-data) type)) | 1621 (mac-coerce-ae-data (car type-data) (cdr type-data) type)) |
1621 (cdr desc))))))) | 1622 (cdr desc))))))) |
1622 | 1623 |
1624 (defun mac-ae-number (ae keyword) | |
1625 (let ((type-data (mac-ae-parameter ae keyword)) | |
1626 str) | |
1627 (if (and type-data | |
1628 (setq str (mac-coerce-ae-data (car type-data) | |
1629 (cdr type-data) "TEXT"))) | |
1630 (string-to-number str) | |
1631 nil))) | |
1632 | |
1623 (defun mac-bytes-to-integer (bytes &optional from to) | 1633 (defun mac-bytes-to-integer (bytes &optional from to) |
1624 (or from (setq from 0)) | 1634 (or from (setq from 0)) |
1625 (or to (setq to (length bytes))) | 1635 (or to (setq to (length bytes))) |
1626 (let* ((len (- to from)) | 1636 (let* ((len (- to from)) |
1627 (extended-sign-len (- (1+ (ceiling (log most-positive-fixnum 2))) | 1637 (extended-sign-len (- (1+ (ceiling (log most-positive-fixnum 2))) |
1632 (aref bytes (+ from (if (eq (byteorder) ?B) i | 1642 (aref bytes (+ from (if (eq (byteorder) ?B) i |
1633 (- len i 1))))))) | 1643 (- len i 1))))))) |
1634 (if (> extended-sign-len 0) | 1644 (if (> extended-sign-len 0) |
1635 (ash (lsh result extended-sign-len) (- extended-sign-len)) | 1645 (ash (lsh result extended-sign-len) (- extended-sign-len)) |
1636 result))) | 1646 result))) |
1637 | |
1638 (defun mac-bytes-to-digits (bytes &optional from to) | |
1639 (or from (setq from 0)) | |
1640 (or to (setq to (length bytes))) | |
1641 (let ((len (- to from)) | |
1642 (val 0.0)) | |
1643 (dotimes (i len) | |
1644 (setq val (+ (* val 256.0) | |
1645 (aref bytes (+ from (if (eq (byteorder) ?B) i | |
1646 (- len i 1))))))) | |
1647 (format "%.0f" val))) | |
1648 | 1647 |
1649 (defun mac-ae-selection-range (ae) | 1648 (defun mac-ae-selection-range (ae) |
1650 ;; #pragma options align=mac68k | 1649 ;; #pragma options align=mac68k |
1651 ;; typedef struct SelectionRange { | 1650 ;; typedef struct SelectionRange { |
1652 ;; short unused1; // 0 (not used) | 1651 ;; short unused1; // 0 (not used) |
1669 (defun mac-ae-text-for-search (ae) | 1668 (defun mac-ae-text-for-search (ae) |
1670 (let ((utf8-text (cdr (mac-ae-parameter ae "stxt" "utf8")))) | 1669 (let ((utf8-text (cdr (mac-ae-parameter ae "stxt" "utf8")))) |
1671 (and utf8-text | 1670 (and utf8-text |
1672 (decode-coding-string utf8-text 'utf-8)))) | 1671 (decode-coding-string utf8-text 'utf-8)))) |
1673 | 1672 |
1673 (defun mac-ae-text (ae) | |
1674 (or (cdr (mac-ae-parameter ae nil "TEXT")) | |
1675 (error "No text in Apple event."))) | |
1676 | |
1677 (defun mac-ae-frame (ae &optional keyword type) | |
1678 (let ((bytes (cdr (mac-ae-parameter ae keyword type)))) | |
1679 (if (or (null bytes) (/= (length bytes) 4)) | |
1680 (error "No window reference in Apple event.") | |
1681 (let ((window-id (mac-coerce-ae-data "long" bytes "TEXT")) | |
1682 (rest (frame-list)) | |
1683 frame) | |
1684 (while (and (null frame) rest) | |
1685 (if (string= (frame-parameter (car rest) 'window-id) window-id) | |
1686 (setq frame (car rest))) | |
1687 (setq rest (cdr rest))) | |
1688 frame)))) | |
1689 | |
1690 (defun mac-ae-script-language (ae keyword) | |
1691 ;; struct WritingCode { | |
1692 ;; ScriptCode theScriptCode; | |
1693 ;; LangCode theLangCode; | |
1694 ;; }; | |
1695 (let ((bytes (cdr (mac-ae-parameter ae keyword "intl")))) | |
1696 (and bytes | |
1697 (cons (mac-bytes-to-integer bytes 0 2) | |
1698 (mac-bytes-to-integer bytes 2 4))))) | |
1699 | |
1700 (defun mac-bytes-to-text-range (bytes &optional from to) | |
1701 ;; struct TextRange { | |
1702 ;; long fStart; | |
1703 ;; long fEnd; | |
1704 ;; short fHiliteStyle; | |
1705 ;; }; | |
1706 (or from (setq from 0)) | |
1707 (or to (setq to (length bytes))) | |
1708 (and (= (- to from) (+ 4 4 2)) | |
1709 (list (mac-bytes-to-integer bytes from (+ from 4)) | |
1710 (mac-bytes-to-integer bytes (+ from 4) (+ from 8)) | |
1711 (mac-bytes-to-integer bytes (+ from 8) to)))) | |
1712 | |
1713 (defun mac-ae-text-range-array (ae keyword) | |
1714 ;; struct TextRangeArray { | |
1715 ;; short fNumOfRanges; | |
1716 ;; TextRange fRange[1]; | |
1717 ;; }; | |
1718 (let* ((bytes (cdr (mac-ae-parameter ae keyword "tray"))) | |
1719 (len (length bytes)) | |
1720 nranges result) | |
1721 (when (and bytes (>= len 2) | |
1722 (progn | |
1723 (setq nranges (mac-bytes-to-integer bytes 0 2)) | |
1724 (= len (+ 2 (* nranges 10))))) | |
1725 (setq result (make-vector nranges nil)) | |
1726 (dotimes (i nranges) | |
1727 (aset result i | |
1728 (mac-bytes-to-text-range bytes (+ (* i 10) 2) | |
1729 (+ (* i 10) 12))))) | |
1730 result)) | |
1731 | |
1674 (defun mac-ae-open-documents (event) | 1732 (defun mac-ae-open-documents (event) |
1675 "Open the documents specified by the Apple event EVENT." | 1733 "Open the documents specified by the Apple event EVENT." |
1676 (interactive "e") | 1734 (interactive "e") |
1677 (let ((ae (mac-event-ae event))) | 1735 (let ((ae (mac-event-ae event))) |
1678 (dolist (file-name (mac-ae-list ae nil 'undecoded-file-name)) | 1736 (dolist (file-name (mac-ae-list ae nil 'undecoded-file-name)) |
1679 (if file-name | 1737 (if file-name |
1680 (dnd-open-local-file (concat "file:" file-name) nil))) | 1738 (dnd-open-local-file |
1739 (concat "file://" | |
1740 (mapconcat 'url-hexify-string | |
1741 (split-string file-name "/") "/")) nil))) | |
1681 (let ((selection-range (mac-ae-selection-range ae)) | 1742 (let ((selection-range (mac-ae-selection-range ae)) |
1682 (search-text (mac-ae-text-for-search ae))) | 1743 (search-text (mac-ae-text-for-search ae))) |
1683 (cond (selection-range | 1744 (cond (selection-range |
1684 (let ((line (car selection-range)) | 1745 (let ((line (car selection-range)) |
1685 (start (cadr selection-range)) | 1746 (start (cadr selection-range)) |
1693 (re-search-forward | 1754 (re-search-forward |
1694 (mapconcat 'regexp-quote (split-string search-text) "\\|") | 1755 (mapconcat 'regexp-quote (split-string search-text) "\\|") |
1695 nil t))))) | 1756 nil t))))) |
1696 (select-frame-set-input-focus (selected-frame))) | 1757 (select-frame-set-input-focus (selected-frame))) |
1697 | 1758 |
1698 (defun mac-ae-text (ae) | |
1699 (or (cdr (mac-ae-parameter ae nil "TEXT")) | |
1700 (error "No text in Apple event."))) | |
1701 | |
1702 (defun mac-ae-get-url (event) | 1759 (defun mac-ae-get-url (event) |
1703 "Open the URL specified by the Apple event EVENT. | 1760 "Open the URL specified by the Apple event EVENT. |
1704 Currently the `mailto' scheme is supported." | 1761 Currently the `mailto' scheme is supported." |
1705 (interactive "e") | 1762 (interactive "e") |
1706 (let* ((ae (mac-event-ae event)) | 1763 (let* ((ae (mac-event-ae event)) |
1707 (parsed-url (url-generic-parse-url (mac-ae-text ae)))) | 1764 (parsed-url (url-generic-parse-url (mac-ae-text ae)))) |
1708 (if (string= (url-type parsed-url) "mailto") | 1765 (if (string= (url-type parsed-url) "mailto") |
1709 (url-mailto parsed-url) | 1766 (url-mailto parsed-url) |
1710 (error "Unsupported URL scheme: %s" (url-type parsed-url))))) | 1767 (mac-resume-apple-event ae t)))) |
1711 | 1768 |
1712 (setq mac-apple-event-map (make-sparse-keymap)) | 1769 (setq mac-apple-event-map (make-sparse-keymap)) |
1713 | 1770 |
1714 ;; Received when Emacs is launched without associated documents. | 1771 ;; Received when Emacs is launched without associated documents. |
1715 ;; Accept it as an Apple event, but no Emacs event is generated so as | 1772 ;; Accept it as an Apple event, but no Emacs event is generated so as |
1741 (let* ((ae (mac-event-ae event)) | 1798 (let* ((ae (mac-event-ae event)) |
1742 (modifiers (cdr (mac-ae-parameter ae "kmod")))) | 1799 (modifiers (cdr (mac-ae-parameter ae "kmod")))) |
1743 (if (and modifiers (not (string= modifiers "\000\000\000\000"))) | 1800 (if (and modifiers (not (string= modifiers "\000\000\000\000"))) |
1744 ;; Globally toggle tool-bar-mode if some modifier key is pressed. | 1801 ;; Globally toggle tool-bar-mode if some modifier key is pressed. |
1745 (tool-bar-mode) | 1802 (tool-bar-mode) |
1746 (let ((window-id (mac-bytes-to-digits (cdr (mac-ae-parameter ae)))) | 1803 (let ((frame (mac-ae-frame ae))) |
1747 (rest (frame-list)) | |
1748 frame) | |
1749 (while (and (null frame) rest) | |
1750 (if (string= (frame-parameter (car rest) 'window-id) window-id) | |
1751 (setq frame (car rest))) | |
1752 (setq rest (cdr rest))) | |
1753 (set-frame-parameter frame 'tool-bar-lines | 1804 (set-frame-parameter frame 'tool-bar-lines |
1754 (if (= (frame-parameter frame 'tool-bar-lines) 0) | 1805 (if (= (frame-parameter frame 'tool-bar-lines) 0) |
1755 1 0)))))) | 1806 1 0)))))) |
1756 | 1807 |
1757 ;; kEventClassWindow/kEventWindowToolbarSwitchMode | 1808 ;; kEventClassWindow/kEventWindowToolbarSwitchMode |
1777 | 1828 |
1778 (defun mac-handle-font-selection (event) | 1829 (defun mac-handle-font-selection (event) |
1779 "Change default face attributes according to font selection EVENT." | 1830 "Change default face attributes according to font selection EVENT." |
1780 (interactive "e") | 1831 (interactive "e") |
1781 (let* ((ae (mac-event-ae event)) | 1832 (let* ((ae (mac-event-ae event)) |
1782 (fm-font-size (cdr (mac-ae-parameter ae "fmsz"))) | 1833 (fm-font-size (mac-ae-number ae "fmsz")) |
1783 (atsu-font-id (cdr (mac-ae-parameter ae "auid"))) | 1834 (atsu-font-id (cdr (mac-ae-parameter ae "auid"))) |
1784 (attribute-values (gethash atsu-font-id mac-atsu-font-table))) | 1835 (attribute-values (gethash atsu-font-id mac-atsu-font-table))) |
1785 (if fm-font-size | 1836 (if fm-font-size |
1786 (setq attribute-values | 1837 (setq attribute-values |
1787 `(:height ,(* 10 (mac-bytes-to-integer fm-font-size)) | 1838 `(:height ,(* 10 fm-font-size) ,@attribute-values))) |
1788 ,@attribute-values))) | |
1789 (apply 'set-face-attribute 'default (selected-frame) attribute-values))) | 1839 (apply 'set-face-attribute 'default (selected-frame) attribute-values))) |
1790 | 1840 |
1791 ;; kEventClassFont/kEventFontPanelClosed | 1841 ;; kEventClassFont/kEventFontPanelClosed |
1792 (define-key mac-apple-event-map [font panel-closed] | 1842 (define-key mac-apple-event-map [font panel-closed] |
1793 'mac-handle-font-panel-closed) | 1843 'mac-handle-font-panel-closed) |
1799 "Font Panel" | 1849 "Font Panel" |
1800 "Show the font panel as a floating dialog") | 1850 "Show the font panel as a floating dialog") |
1801 'showhide-speedbar) | 1851 'showhide-speedbar) |
1802 | 1852 |
1803 ) ;; (fboundp 'mac-set-font-panel-visibility) | 1853 ) ;; (fboundp 'mac-set-font-panel-visibility) |
1854 | |
1855 ;;; Text Services | |
1856 (defvar mac-ts-active-input-buf "" | |
1857 "Byte sequence of the current Mac TSM active input area.") | |
1858 (defvar mac-ts-update-active-input-area-seqno 0 | |
1859 "Number of processed update-active-input-area events.") | |
1860 (setq mac-ts-active-input-overlay (make-overlay 0 0)) | |
1861 | |
1862 (defface mac-ts-caret-position | |
1863 '((t :inverse-video t)) | |
1864 "Face for caret position in Mac TSM active input area. | |
1865 This is used only when the active input area is displayed in the | |
1866 echo area." | |
1867 :group 'mac) | |
1868 | |
1869 (defface mac-ts-raw-text | |
1870 '((t :underline t)) | |
1871 "Face for raw text in Mac TSM active input area." | |
1872 :group 'mac) | |
1873 | |
1874 (defface mac-ts-selected-raw-text | |
1875 '((t :underline t)) | |
1876 "Face for selected raw text in Mac TSM active input area." | |
1877 :group 'mac) | |
1878 | |
1879 (defface mac-ts-converted-text | |
1880 '((((background dark)) :underline "gray20") | |
1881 (t :underline "gray80")) | |
1882 "Face for converted text in Mac TSM active input area." | |
1883 :group 'mac) | |
1884 | |
1885 (defface mac-ts-selected-converted-text | |
1886 '((t :underline t)) | |
1887 "Face for selected converted text in Mac TSM active input area." | |
1888 :group 'mac) | |
1889 | |
1890 (defface mac-ts-block-fill-text | |
1891 '((t :underline t)) | |
1892 "Face for block fill text in Mac TSM active input area." | |
1893 :group 'mac) | |
1894 | |
1895 (defface mac-ts-outline-text | |
1896 '((t :underline t)) | |
1897 "Face for outline text in Mac TSM active input area." | |
1898 :group 'mac) | |
1899 | |
1900 (defface mac-ts-selected-text | |
1901 '((t :underline t)) | |
1902 "Face for selected text in Mac TSM active input area." | |
1903 :group 'mac) | |
1904 | |
1905 (defface mac-ts-no-hilite | |
1906 '((t :inherit default)) | |
1907 "Face for no hilite in Mac TSM active input area." | |
1908 :group 'mac) | |
1909 | |
1910 (defconst mac-ts-hilite-style-faces | |
1911 '((2 . mac-ts-raw-text) ; kTSMHiliteRawText | |
1912 (3 . mac-ts-selected-raw-text) ; kTSMHiliteSelectedRawText | |
1913 (4 . mac-ts-converted-text) ; kTSMHiliteConvertedText | |
1914 (5 . mac-ts-selected-converted-text) ; kTSMHiliteSelectedConvertedText | |
1915 (6 . mac-ts-block-fill-text) ; kTSMHiliteBlockFillText | |
1916 (7 . mac-ts-outline-text) ; kTSMHiliteOutlineText | |
1917 (8 . mac-ts-selected-text) ; kTSMHiliteSelectedText | |
1918 (9 . mac-ts-no-hilite)) ; kTSMHiliteNoHilite | |
1919 "Alist of Mac TSM hilite style vs Emacs face.") | |
1920 | |
1921 (defun mac-ts-update-active-input-buf (text fix-len hilite-rng update-rng) | |
1922 (let ((buf-len (length mac-ts-active-input-buf)) | |
1923 confirmed) | |
1924 (if (or (null update-rng) | |
1925 (/= (% (length update-rng) 2) 0)) | |
1926 ;; The parameter is missing (or in a bad format). The | |
1927 ;; existing inline input session is completely replaced with | |
1928 ;; the new text. | |
1929 (setq mac-ts-active-input-buf text) | |
1930 ;; Otherwise, the current subtext specified by the (2*j)-th | |
1931 ;; range is replaced with the new subtext specified by the | |
1932 ;; (2*j+1)-th range. | |
1933 (let ((tail buf-len) | |
1934 (i (length update-rng)) | |
1935 segments rng) | |
1936 (while (> i 0) | |
1937 (setq i (- i 2)) | |
1938 (setq rng (aref update-rng i)) | |
1939 (if (and (<= 0 (cadr rng)) (< (cadr rng) tail) | |
1940 (<= tail buf-len)) | |
1941 (setq segments | |
1942 (cons (substring mac-ts-active-input-buf (cadr rng) tail) | |
1943 segments))) | |
1944 (setq tail (car rng)) | |
1945 (setq rng (aref update-rng (1+ i))) | |
1946 (if (and (<= 0 (car rng)) (< (car rng) (cadr rng)) | |
1947 (<= (cadr rng) (length text))) | |
1948 (setq segments | |
1949 (cons (substring text (car rng) (cadr rng)) | |
1950 segments)))) | |
1951 (if (and (< 0 tail) (<= tail buf-len)) | |
1952 (setq segments | |
1953 (cons (substring mac-ts-active-input-buf 0 tail) | |
1954 segments))) | |
1955 (setq mac-ts-active-input-buf (apply 'concat segments)))) | |
1956 (setq buf-len (length mac-ts-active-input-buf)) | |
1957 ;; Confirm (a part of) inline input session. | |
1958 (cond ((< fix-len 0) | |
1959 ;; Entire inline session is being confirmed. | |
1960 (setq confirmed mac-ts-active-input-buf) | |
1961 (setq mac-ts-active-input-buf "")) | |
1962 ((= fix-len 0) | |
1963 ;; None of the text is being confirmed (yet). | |
1964 (setq confirmed "")) | |
1965 (t | |
1966 (if (> fix-len buf-len) | |
1967 (setq fix-len buf-len)) | |
1968 (setq confirmed (substring mac-ts-active-input-buf 0 fix-len)) | |
1969 (setq mac-ts-active-input-buf | |
1970 (substring mac-ts-active-input-buf fix-len)))) | |
1971 (setq buf-len (length mac-ts-active-input-buf)) | |
1972 ;; Update highlighting and the caret position in the new inline | |
1973 ;; input session. | |
1974 (remove-text-properties 0 buf-len '(cursor nil) mac-ts-active-input-buf) | |
1975 (mapc (lambda (rng) | |
1976 (cond ((and (= (nth 2 rng) 1) ; kTSMHiliteCaretPosition | |
1977 (<= 0 (car rng)) (< (car rng) buf-len)) | |
1978 (put-text-property (car rng) buf-len | |
1979 'cursor t mac-ts-active-input-buf)) | |
1980 ((and (<= 0 (car rng)) (< (car rng) (cadr rng)) | |
1981 (<= (cadr rng) buf-len)) | |
1982 (put-text-property (car rng) (cadr rng) 'face | |
1983 (cdr (assq (nth 2 rng) | |
1984 mac-ts-hilite-style-faces)) | |
1985 mac-ts-active-input-buf)))) | |
1986 hilite-rng) | |
1987 confirmed)) | |
1988 | |
1989 (defun mac-split-string-by-property-change (string) | |
1990 (let ((tail (length string)) | |
1991 head result) | |
1992 (unless (= tail 0) | |
1993 (while (setq head (previous-property-change tail string) | |
1994 result (cons (substring string (or head 0) tail) result) | |
1995 tail head))) | |
1996 result)) | |
1997 | |
1998 (defun mac-replace-untranslated-utf-8-chars (string &optional to-string) | |
1999 (or to-string (setq to-string "$,3u=(B")) | |
2000 (mapconcat | |
2001 (lambda (str) | |
2002 (if (get-text-property 0 'untranslated-utf-8 str) to-string str)) | |
2003 (mac-split-string-by-property-change string) | |
2004 "")) | |
2005 | |
2006 (defun mac-ts-update-active-input-area (event) | |
2007 "Update Mac TSM active input area according to EVENT. | |
2008 The confirmed text is converted to Emacs input events and pushed | |
2009 into `unread-command-events'. The unconfirmed text is displayed | |
2010 either in the current buffer or in the echo area." | |
2011 (interactive "e") | |
2012 (let* ((ae (mac-event-ae event)) | |
2013 (text (or (cdr (mac-ae-parameter ae "tstx" "utxt")) "")) | |
2014 (script-language (mac-ae-script-language ae "tssl")) | |
2015 (coding (or (cdr (assq (car script-language) | |
2016 mac-script-code-coding-systems)) | |
2017 'mac-roman)) | |
2018 (fix-len (mac-bytes-to-integer | |
2019 (cdr (mac-ae-parameter ae "tsfx" "long")))) | |
2020 ;; Optional parameters | |
2021 (hilite-rng (mac-ae-text-range-array ae "tshi")) | |
2022 (update-rng (mac-ae-text-range-array ae "tsup")) | |
2023 ;;(pin-rng (mac-bytes-to-text-range (cdr (mac-ae-parameter ae "tspn" "txrn")))) | |
2024 ;;(clause-offsets (cdr (mac-ae-parameter ae "tscl" "ofay"))) | |
2025 (seqno (mac-ae-number ae "tsSn")) | |
2026 confirmed) | |
2027 (unless (= seqno mac-ts-update-active-input-area-seqno) | |
2028 ;; Reset internal states if sequence number is out of sync. | |
2029 (setq mac-ts-active-input-buf "")) | |
2030 (setq confirmed | |
2031 (mac-ts-update-active-input-buf text fix-len hilite-rng update-rng)) | |
2032 (let ((use-echo-area | |
2033 (or isearch-mode | |
2034 (and cursor-in-echo-area (current-message)) | |
2035 ;; Overlay strings are not shown in some cases. | |
2036 (get-char-property (point) 'display) | |
2037 (get-char-property (point) 'invisible) | |
2038 (get-char-property (point) 'composition))) | |
2039 active-input-string caret-seen) | |
2040 ;; Decode the active input area text with inheriting faces and | |
2041 ;; the caret position. | |
2042 (setq active-input-string | |
2043 (mapconcat | |
2044 (lambda (str) | |
2045 (let ((decoded (mac-utxt-to-string str coding))) | |
2046 (put-text-property 0 (length decoded) 'face | |
2047 (get-text-property 0 'face str) decoded) | |
2048 (when (and (not caret-seen) | |
2049 (get-text-property 0 'cursor str)) | |
2050 (setq caret-seen t) | |
2051 (if use-echo-area | |
2052 (put-text-property 0 1 'face 'mac-ts-caret-position | |
2053 decoded) | |
2054 (put-text-property 0 1 'cursor t decoded))) | |
2055 decoded)) | |
2056 (mac-split-string-by-property-change mac-ts-active-input-buf) | |
2057 "")) | |
2058 (put-text-property 0 (length active-input-string) | |
2059 'mac-ts-active-input-string t active-input-string) | |
2060 (if use-echo-area | |
2061 (let (msg message-log-max) | |
2062 (if (and (current-message) | |
2063 ;; Don't get confused by previously displayed | |
2064 ;; `active-input-string'. | |
2065 (null (get-text-property 0 'mac-ts-active-input-string | |
2066 (current-message)))) | |
2067 (setq msg (propertize (current-message) 'display | |
2068 (concat (current-message) | |
2069 active-input-string))) | |
2070 (setq msg active-input-string)) | |
2071 (message "%s" msg) | |
2072 (overlay-put mac-ts-active-input-overlay 'before-string nil)) | |
2073 (move-overlay mac-ts-active-input-overlay | |
2074 (point) (point) (current-buffer)) | |
2075 (overlay-put mac-ts-active-input-overlay 'before-string | |
2076 active-input-string)) | |
2077 ;; Unread confirmed characters and insert them in a keyboard | |
2078 ;; macro being defined. | |
2079 (apply 'isearch-unread | |
2080 (append (mac-replace-untranslated-utf-8-chars | |
2081 (mac-utxt-to-string confirmed coding)) '()))) | |
2082 ;; The event is successfully processed. Sync the sequence number. | |
2083 (setq mac-ts-update-active-input-area-seqno (1+ seqno)))) | |
2084 | |
2085 (defun mac-ts-unicode-for-key-event (event) | |
2086 "Convert Unicode key EVENT to Emacs key events and unread them." | |
2087 (interactive "e") | |
2088 (let* ((ae (mac-event-ae event)) | |
2089 (text (cdr (mac-ae-parameter ae "tstx" "utxt"))) | |
2090 (script-language (mac-ae-script-language ae "tssl")) | |
2091 (coding (or (cdr (assq (car script-language) | |
2092 mac-script-code-coding-systems)) | |
2093 'mac-roman))) | |
2094 ;; Unread characters and insert them in a keyboard macro being | |
2095 ;; defined. | |
2096 (apply 'isearch-unread | |
2097 (append (mac-replace-untranslated-utf-8-chars | |
2098 (mac-utxt-to-string text coding)) '())))) | |
2099 | |
2100 ;; kEventClassTextInput/kEventTextInputUpdateActiveInputArea | |
2101 (define-key mac-apple-event-map [text-input update-active-input-area] | |
2102 'mac-ts-update-active-input-area) | |
2103 ;; kEventClassTextInput/kEventTextInputUnicodeForKeyEvent | |
2104 (define-key mac-apple-event-map [text-input unicode-for-key-event] | |
2105 'mac-ts-unicode-for-key-event) | |
1804 | 2106 |
1805 ;;; Services | 2107 ;;; Services |
1806 (defun mac-service-open-file () | 2108 (defun mac-service-open-file () |
1807 "Open the file specified by the selection value for Services." | 2109 "Open the file specified by the selection value for Services." |
1808 (interactive) | 2110 (interactive) |
1855 | 2157 |
1856 (defun mac-dispatch-apple-event (event) | 2158 (defun mac-dispatch-apple-event (event) |
1857 "Dispatch EVENT according to the keymap `mac-apple-event-map'." | 2159 "Dispatch EVENT according to the keymap `mac-apple-event-map'." |
1858 (interactive "e") | 2160 (interactive "e") |
1859 (let* ((binding (lookup-key mac-apple-event-map (mac-event-spec event))) | 2161 (let* ((binding (lookup-key mac-apple-event-map (mac-event-spec event))) |
1860 (service-message | 2162 (ae (mac-event-ae event)) |
1861 (and (keymapp binding) | 2163 (service-message (and (keymapp binding) |
1862 (cdr (mac-ae-parameter (mac-event-ae event) "svmg"))))) | 2164 (cdr (mac-ae-parameter ae "svmg"))))) |
1863 (when service-message | 2165 (when service-message |
1864 (setq service-message | 2166 (setq service-message |
1865 (intern (decode-coding-string service-message 'utf-8))) | 2167 (intern (decode-coding-string service-message 'utf-8))) |
1866 (setq binding (lookup-key binding (vector service-message)))) | 2168 (setq binding (lookup-key binding (vector service-message)))) |
1867 ;; Replace (cadr event) with a dummy position so that event-start | 2169 ;; Replace (cadr event) with a dummy position so that event-start |
1868 ;; returns it. | 2170 ;; returns it. |
1869 (setcar (cdr event) (list (selected-window) (point) '(0 . 0) 0)) | 2171 (setcar (cdr event) (list (selected-window) (point) '(0 . 0) 0)) |
1870 (call-interactively binding))) | 2172 (if (null (mac-ae-parameter ae 'emacs-suspension-id)) |
1871 | 2173 (command-execute binding nil (vector event) t) |
1872 (global-set-key [mac-apple-event] 'mac-dispatch-apple-event) | 2174 (condition-case err |
2175 (progn | |
2176 (command-execute binding nil (vector event) t) | |
2177 (mac-resume-apple-event ae)) | |
2178 (error | |
2179 (mac-ae-set-reply-parameter ae "errs" | |
2180 (cons "TEXT" (error-message-string err))) | |
2181 (mac-resume-apple-event ae -10000)))))) ; errAEEventFailed | |
2182 | |
2183 (define-key special-event-map [mac-apple-event] 'mac-dispatch-apple-event) | |
1873 | 2184 |
1874 ;; Processing of Apple events are deferred at the startup time. For | 2185 ;; Processing of Apple events are deferred at the startup time. For |
1875 ;; example, files dropped onto the Emacs application icon can only be | 2186 ;; example, files dropped onto the Emacs application icon can only be |
1876 ;; processed when the initial frame has been created: this is where | 2187 ;; processed when the initial frame has been created: this is where |
1877 ;; the files should be opened. | 2188 ;; the files should be opened. |
1878 (add-hook 'after-init-hook 'mac-process-deferred-apple-events) | 2189 (add-hook 'after-init-hook 'mac-process-deferred-apple-events) |
2190 | |
2191 (run-with-idle-timer 5 t 'mac-cleanup-expired-apple-events) | |
1879 | 2192 |
1880 | 2193 |
1881 ;;;; Drag and drop | 2194 ;;;; Drag and drop |
1882 | 2195 |
1883 (defcustom mac-dnd-types-alist | 2196 (defcustom mac-dnd-types-alist |