comparison lisp/term/ns-win.el @ 102253:8a3d30f9b513

(ns-working-overlay): Don't make it buffer-local. (ns-working-overlay-len): Remove. Use ns-working-overlay instead. (ns-delete-working-text): Merge with ns-unecho-working-text. Decide which to use based on ns-working-overlay. (ns-unecho-working-text): Remove. (ns-insert-working-text, ns-echo-working-text): Adjust accordingly.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 24 Feb 2009 21:11:53 +0000
parents 9f9c03710f3b
children 291f6c889881
comparison
equal deleted inserted replaced
102252:d154d78e56fb 102253:8a3d30f9b513
777 777
778 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 778 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
779 779
780 780
781 781
782 ;;;; Composed key sequence handling for Nextstep system input methods. 782 ;; Composed key sequence handling for Nextstep system input methods.
783 ;;;; (On Nextstep systems, input methods are provided for CJK 783 ;; (On Nextstep systems, input methods are provided for CJK
784 ;;;; characters, etc. which require multiple keystrokes, and during 784 ;; characters, etc. which require multiple keystrokes, and during
785 ;;;; entry a partial ("working") result is typically shown in the 785 ;; entry a partial ("working") result is typically shown in the
786 ;;;; editing window.) 786 ;; editing window.)
787 787
788 (defface ns-working-text-face 788 (defface ns-working-text-face
789 '((t :underline t)) 789 '((t :underline t))
790 "Face used to highlight working text during compose sequence insert." 790 "Face used to highlight working text during compose sequence insert."
791 :group 'ns) 791 :group 'ns)
792 792
793 (defvar ns-working-overlay nil 793 (defvar ns-working-overlay nil
794 "Overlay used to highlight working text during compose sequence insert.") 794 "Overlay used to highlight working text during compose sequence insert.
795 (make-variable-buffer-local 'ns-working-overlay) 795 When text is in th echo area, this just stores the length of the working text.")
796 (defvar ns-working-overlay-len 0
797 "Length of working text during compose sequence insert.")
798 (make-variable-buffer-local 'ns-working-overlay-len)
799 796
800 (defvar ns-working-text) ; nsterm.m 797 (defvar ns-working-text) ; nsterm.m
801 798
802 ;; Test if in echo area, based on mac-win.el 2007/08/26 unicode-2. 799 ;; Test if in echo area, based on mac-win.el 2007/08/26 unicode-2.
803 ;; This will fail if called from a NONASCII_KEYSTROKE event on the global map. 800 ;; This will fail if called from a NONASCII_KEYSTROKE event on the global map.
823 (defun ns-put-working-text () 820 (defun ns-put-working-text ()
824 (interactive) 821 (interactive)
825 (if (ns-in-echo-area) (ns-echo-working-text) (ns-insert-working-text))) 822 (if (ns-in-echo-area) (ns-echo-working-text) (ns-insert-working-text)))
826 (defun ns-unput-working-text () 823 (defun ns-unput-working-text ()
827 (interactive) 824 (interactive)
828 (if (ns-in-echo-area) (ns-unecho-working-text) (ns-delete-working-text))) 825 (ns-delete-working-text))
829 826
830 (defun ns-insert-working-text () 827 (defun ns-insert-working-text ()
831 "Insert contents of ns-working-text as UTF8 string and mark with 828 "Insert contents of `ns-working-text' as UTF8 string and mark with
832 ns-working-overlay. Any previously existing working text is cleared first. 829 `ns-working-overlay'. Any previously existing working text is cleared first.
833 The overlay is assigned the face ns-working-text-face." 830 The overlay is assigned the face `ns-working-text-face'."
834 ;; FIXME: if buffer is read-only, don't try to insert anything 831 ;; FIXME: if buffer is read-only, don't try to insert anything
835 ;; and if text is bound to a command, execute that instead (Bug#1453) 832 ;; and if text is bound to a command, execute that instead (Bug#1453)
836 (interactive) 833 (interactive)
837 (if ns-working-overlay (ns-delete-working-text)) 834 (ns-delete-working-text)
838 (let ((start (point))) 835 (let ((start (point)))
839 (insert ns-working-text) 836 (insert ns-working-text)
840 (overlay-put (setq ns-working-overlay (make-overlay start (point) 837 (overlay-put (setq ns-working-overlay (make-overlay start (point)
841 (current-buffer) nil t)) 838 (current-buffer) nil t))
842 'face 'ns-working-text-face) 839 'face 'ns-working-text-face)))
843 (setq ns-working-overlay-len (+ ns-working-overlay-len (- (point) start)))))
844 840
845 (defun ns-echo-working-text () 841 (defun ns-echo-working-text ()
846 "Echo contents of ns-working-text in message display area. 842 "Echo contents of ns-working-text in message display area.
847 See ns-insert-working-text." 843 See `ns-insert-working-text'."
848 (if ns-working-overlay (ns-unecho-working-text)) 844 (ns-delete-working-text)
849 (let* ((msg (current-message)) 845 (let* ((msg (current-message))
850 (msglen (length msg)) 846 (msglen (length msg))
851 message-log-max) 847 message-log-max)
852 (setq ns-working-overlay-len (length ns-working-text)) 848 (setq ns-working-overlay (length ns-working-text))
853 (setq msg (concat msg ns-working-text)) 849 (setq msg (concat msg ns-working-text))
854 (put-text-property msglen (+ msglen ns-working-overlay-len) 850 (put-text-property msglen (+ msglen ns-working-overlay)
855 'face 'ns-working-text-face msg) 851 'face 'ns-working-text-face msg)
856 (message "%s" msg) 852 (message "%s" msg)))
857 (setq ns-working-overlay t)))
858 853
859 (defun ns-delete-working-text() 854 (defun ns-delete-working-text()
860 "Delete working text and clear ns-working-overlay." 855 "Delete working text and clear `ns-working-overlay'."
861 (interactive) 856 (interactive)
862 (delete-backward-char ns-working-overlay-len) 857 (cond
863 (setq ns-working-overlay-len 0) 858 ((and (overlayp ns-working-overlay)
864 (delete-overlay ns-working-overlay)) 859 ;; Still alive?
865 860 (overlay-buffer ns-working-overlay))
866 (defun ns-unecho-working-text() 861 (with-current-buffer (overlay-buffer ns-working-overlay)
867 "Delete working text from echo area and clear ns-working-overlay." 862 (delete-region (overlay-start ns-working-overlay)
868 (let ((msg (current-message)) 863 (overlay-end ns-working-overlay))
869 message-log-max) 864 (delete-overlay ns-working-overlay)))
870 (setq msg (substring msg 0 (- (length msg) ns-working-overlay-len))) 865 ((integerp ns-working-overlay)
871 (message "%s" msg) 866 (let ((msg (current-message))
872 (setq ns-working-overlay-len 0) 867 message-log-max)
873 (setq ns-working-overlay nil))) 868 (setq msg (substring msg 0 (- (length msg) ns-working-overlay)))
869 (message "%s" msg))))
870 (setq ns-working-overlay nil))
874 871
875 872
876 (declare-function ns-convert-utf8-nfd-to-nfc "nsfns.m" (str)) 873 (declare-function ns-convert-utf8-nfd-to-nfc "nsfns.m" (str))
877 874
878 ;;;; OS X file system Unicode UTF-8 NFD (decomposed form) support 875 ;;;; OS X file system Unicode UTF-8 NFD (decomposed form) support