all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Keitaro Miyazaki <keitaro.miyazaki@gmail.com>
To: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Cc: 7282@debbugs.gnu.org
Subject: bug#7282: 23.2; [PATCH] Improve text composition by Input Methods on MacOSX.
Date: Fri, 29 Oct 2010 00:31:09 +0900	[thread overview]
Message-ID: <AANLkTimfFP0eMLZHKfe-fEbe5yWp+ncTAX9DRNpJM63o@mail.gmail.com> (raw)
In-Reply-To: <wl39rqsu2t.wl%mituharu@math.s.chiba-u.ac.jp>

[-- Attachment #1: Type: text/plain, Size: 570 bytes --]

> I mentioned "non-BMP characters" in the previous reply.

I understood that NSString counts numbers of UTF-16 units
instead of numbers of characters, so NSString counts length
of a non-BMP character as 2.

Thanks for your detailed description.


I fixed my patch to adjust the numbers in `selectedRange',
so that emacs can recognize the range properly.

Attached patch also includes the patch `im-cursor-position-fix.diff',
so you don't need to apply it now.


...BTW, I tried your Mac port today, and it seems to be working
fine for me. I hope it will be merged soon.

[-- Attachment #2: highlight-on-active-clause-v2.diff --]
[-- Type: application/octet-stream, Size: 4797 bytes --]

diff -Nrpu emacs-23.2.orig/lisp/term/ns-win.el emacs-23.2/lisp/term/ns-win.el
--- emacs-23.2.orig/lisp/term/ns-win.el	2010-04-04 07:26:08.000000000 +0900
+++ emacs-23.2/lisp/term/ns-win.el	2010-10-28 23:33:11.000000000 +0900
@@ -551,10 +551,19 @@ The properties returned may include `top
   "Face used to highlight working text during compose sequence insert."
   :group 'ns)
 
+(defface ns-active-clause-face
+  '((t :inherit ns-working-text-face :inverse-video t))
+  "Face used to highlight active clause of working text during compose sequence insert."
+  :group 'ns)
+
 (defvar ns-working-overlay nil
   "Overlay used to highlight working text during compose sequence insert.
 When text is in th echo area, this just stores the length of the working text.")
 
+(defvar ns-active-clause-overlay nil
+  "Overlay used to highlight active clause of working text during compose sequence insert.
+When text is in th echo area, this just stores the length of the working text.")
+
 (defvar ns-working-text)		; nsterm.m
 
 ;; Test if in echo area, based on mac-win.el 2007/08/26 unicode-2.
@@ -593,11 +602,20 @@ The overlay is assigned the face `ns-wor
   ;;  and if text is bound to a command, execute that instead (Bug#1453)
   (interactive)
   (ns-delete-working-text)
-  (let ((start (point)))
+  (let* ((start (point))
+         (ac-start (+ start (car ns-range-of-active-clause)))
+         (ac-end   (+ start (cdr ns-range-of-active-clause))))
     (insert ns-working-text)
     (overlay-put (setq ns-working-overlay (make-overlay start (point)
 							(current-buffer) nil t))
-		 'face 'ns-working-text-face)))
+		 'face 'ns-working-text-face)
+    (overlay-put (setq ns-active-clause-overlay
+                       (make-overlay ac-start
+                                     ac-end
+                                     nil t))
+                 'face 'ns-active-clause-face)
+    (when (= ac-start ac-end)
+      (goto-char ac-end))))
 
 (defun ns-echo-working-text ()
   "Echo contents of `ns-working-text' in message display area.
@@ -622,7 +640,8 @@ See `ns-insert-working-text'."
     (with-current-buffer (overlay-buffer ns-working-overlay)
       (delete-region (overlay-start ns-working-overlay)
                      (overlay-end ns-working-overlay))
-      (delete-overlay ns-working-overlay)))
+      (delete-overlay ns-working-overlay)
+      (delete-overlay ns-active-clause-overlay)))
    ((integerp ns-working-overlay)
     (let ((msg (current-message))
           message-log-max)
diff -Nrpu emacs-23.2.orig/src/nsterm.m emacs-23.2/src/nsterm.m
--- emacs-23.2.orig/src/nsterm.m	2010-04-04 07:26:04.000000000 +0900
+++ emacs-23.2/src/nsterm.m	2010-10-28 23:32:53.000000000 +0900
@@ -138,6 +138,7 @@ static unsigned convert_ns_to_X_keysym[]
 /* Lisp communications */
 Lisp_Object ns_input_file, ns_input_font, ns_input_fontsize, ns_input_line;
 Lisp_Object ns_input_color, ns_input_text, ns_working_text;
+Lisp_Object ns_range_of_active_clause;
 Lisp_Object ns_input_spi_name, ns_input_spi_arg;
 Lisp_Object Vx_toolkit_scroll_bars;
 static Lisp_Object Qmodifier_value;
@@ -4575,6 +4576,21 @@ ns_term_shutdown (int sig)
   workingText = [str copy];
   ns_working_text = build_string ([workingText UTF8String]);
 
+  /* NSString seems to be counting number of UTF-16 code units instead of
+     number of characters when calculating length of strings.
+     This causes NSString to count length of a non-BMP character as two,
+     not as one.
+     
+     Emacs expects that the length of a non-BMP character as one, so we
+     should adjust numbers in `selectedRange' before passing them to emacs,
+     in case of non-BMP characters are contained in the marked text. */
+  NSString *strToMin = [str substringWithRange: NSMakeRange (0, selRange.location)];
+  NSString *strToMax = [str substringWithRange: NSMakeRange (0, NSMaxRange (selRange))];
+  
+  /* Save the selected range, which was recalculated by emacs. */
+  ns_range_of_active_clause = Fcons (Flength (build_string ([strToMin UTF8String])),
+                                     Flength (build_string ([strToMax UTF8String])));
+
   emacs_event->kind = NS_TEXT_EVENT;
   emacs_event->code = KEY_NS_PUT_WORKING_TEXT;
   EV_TRAILER ((id)nil);
@@ -6167,6 +6183,12 @@ syms_of_nsterm ()
               "String for visualizing working composition sequence.");
   ns_working_text =Qnil;
 
+  DEFVAR_LISP ("ns-range-of-active-clause", &ns_range_of_active_clause,
+              "Range of an active clause in composition sequence. \
+The value is a cons which holds start point of active clause in working \
+text as car, and end point as cdr.");
+  ns_range_of_active_clause =Qnil;
+
   DEFVAR_LISP ("ns-input-font", &ns_input_font,
               "The font specified in the last NS event.");
   ns_input_font =Qnil;

  reply	other threads:[~2010-10-28 15:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-26 12:20 bug#7282: 23.2; [PATCH] Improve text composition by Input Methods on MacOSX Keitaro Miyazaki
2010-10-27  5:46 ` YAMAMOTO Mitsuharu
2010-10-27  6:17   ` YAMAMOTO Mitsuharu
2010-10-27 14:56     ` Keitaro Miyazaki
2010-10-28  0:55       ` YAMAMOTO Mitsuharu
2010-10-28  6:15         ` Keitaro Miyazaki
2010-10-28  6:35           ` YAMAMOTO Mitsuharu
2010-10-28 15:31             ` Keitaro Miyazaki [this message]
2016-07-10 15:15               ` Alan Third
2017-12-27  0:14                 ` Alan Third

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTimfFP0eMLZHKfe-fEbe5yWp+ncTAX9DRNpJM63o@mail.gmail.com \
    --to=keitaro.miyazaki@gmail.com \
    --cc=7282@debbugs.gnu.org \
    --cc=mituharu@math.s.chiba-u.ac.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.