unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
@ 2017-09-26  4:38 Keith David Bershatsky
  2017-09-26 18:46 ` Philipp Stephani
  2017-09-26 23:19 ` YAMAMOTO Mitsuharu
  0 siblings, 2 replies; 14+ messages in thread
From: Keith David Bershatsky @ 2017-09-26  4:38 UTC (permalink / raw)
  To: Emacs Devel

I am working on implementing my own feature requests to draw crosshairs (#17684) using multiple fake cursors (#22873), and I am trying to quickly convert (in C) the :background of the region face into a string -- e.g., "blue" or "#0000FF".  My goal is to do all of this in C, and I would like to avoid porting (rewriting) several Lisp functions to give me the result of:

    (face-attribute 'region :background (selected-frame) 'default)

Is there anything built-in into the Emacs C code base that already does this, or *almost* does this ...?

BACKGROUND:  I already have a function written in C that converts a color string (e.g., "blue" or "#0000FF") into an LSL color vector, which is used by the new multiple fake cursors (#22873) feature.  I erase glyphless (floating) fake cursors by drawing new ones that match the background face.  When a region is active, I need the LSL color vector of the region :background.

Thanks,

Keith



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
@ 2017-09-26 18:38 Keith David Bershatsky
  2017-09-29 13:25 ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Keith David Bershatsky @ 2017-09-26 18:38 UTC (permalink / raw)
  To: emacs-devel

I have begun porting the two relevant Lisp functions to C and will submit them (when finished) in conjunction with the next draft of implementing my feature requests for crosshairs (#17684) and multiple fake cursors (#22873).  I may end up needing some help with some portions of the conversion, but it does not look as difficult as I had initially thought.

DEFUN ("mc-face-attribute", Fmc_face_attribute, Smc_face_attribute, 2, 4, 0,
       doc: /* Return the value of FACE's ATTRIBUTE on FRAME.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
If INHERIT is nil, only attributes directly defined by FACE are considered,
  so the return value may be `unspecified', or a relative value.
If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
  faces specified by its `:inherit' attribute; however the return value
  may still be `unspecified' or relative.
If INHERIT is a face or a list of faces, then the result is further merged
  with that face (or faces), until it becomes specified and absolute.
To ensure that the return value is always specified and absolute, use a
value of `default' for INHERIT; this will resolve any unspecified or
relative values by merging with the `default' face (which is always
completely specified). */)
     (Lisp_Object face, Lisp_Object attribute, Lisp_Object frame, Lisp_Object inherit)
{
  (let ((value (internal-get-lisp-face-attribute face attribute frame)))
    (when (and inherit (face-attribute-relative-p attribute value))
      (let ((inh-from (mc-face-attribute face :inherit frame)))
  (unless (or (null inh-from) (eq inh-from 'unspecified))
          (condition-case nil
              (setq value
                    (mc-face-attribute-merged-with attribute value inh-from frame))
            (error nil)))))
    (when (and inherit
         (not (eq inherit t))
         (face-attribute-relative-p attribute value))
      (setq value (mc-face-attribute-merged-with attribute value inherit frame)))
    value)
}

DEFUN ("mc-face-attribute-merged-with", Fmc_face_attribute_merged_with, Smc_face_attribute_merged_with, 3, 4, 0,
       doc: /* Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
FACES may be either a single face or a list of faces.
[This is an internal function.] */)
     (Lisp_Object attribute, Lisp_Object value, Lisp_Object faces, Lisp_Object frame)
{
  (cond
    ((not (face-attribute-relative-p attribute value))
       value)
    ((null faces)
       value)
    ((consp faces)
      (mc-face-attribute-merged-with
        attribute
        (mc-face-attribute-merged-with attribute value (car faces) frame)
        (cdr faces)
        frame))
    (t
      (merge-face-attribute attribute value (mc-face-attribute faces attribute frame t))))
}



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
  2017-09-26  4:38 Keith David Bershatsky
@ 2017-09-26 18:46 ` Philipp Stephani
  2017-09-26 23:19 ` YAMAMOTO Mitsuharu
  1 sibling, 0 replies; 14+ messages in thread
From: Philipp Stephani @ 2017-09-26 18:46 UTC (permalink / raw)
  To: Keith David Bershatsky, Emacs Devel

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

Keith David Bershatsky <esq@lawlist.com> schrieb am Di., 26. Sep. 2017 um
06:38 Uhr:

> I am working on implementing my own feature requests to draw crosshairs
> (#17684) using multiple fake cursors (#22873), and I am trying to quickly
> convert (in C) the :background of the region face into a string -- e.g.,
> "blue" or "#0000FF".  My goal is to do all of this in C, and I would like
> to avoid porting (rewriting) several Lisp functions to give me the result
> of:
>
>     (face-attribute 'region :background (selected-frame) 'default)
>
> Is there anything built-in into the Emacs C code base that already does
> this, or *almost* does this ...?
>

You can easily call Lisp functions from C.

// In syms_of_...
DEFSYM (Qface_attribute, "face-attribyte");
DEFSYM (Qregion, "region");
DEFSYM (QCbackground, ":background");
DEFSYM (Qdefault, "default");

// Calling
Lisp_Object o = CALLN (Ffuncall, Qface_attribute, Qregion, QCbackground,
Fselected_frame (), Qdefault);

[-- Attachment #2: Type: text/html, Size: 1414 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
@ 2017-09-26 22:06 Keith David Bershatsky
  0 siblings, 0 replies; 14+ messages in thread
From: Keith David Bershatsky @ 2017-09-26 22:06 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: emacs-devel

Thank you, Philipp, for reading this thread and for teaching me how to call a Lisp function from C.

Converting those functions form Lisp to C has been something that I have wanted to do for quite some time, but have admittedly been intimidated because they both use recursion.  I have created a working draft in C that has everything (I think) except for `condition_case`, because I haven't learned how to do that in C yet.  I'll carbon copy you with the rough draft.

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [09-26-2017 11:46:05] <26 Sep 2017 18:46:05 +0000>
FROM:  Philipp Stephani <p.stephani2@gmail.com>
> 
> * * *
> 
> You can easily call Lisp functions from C.
> 
> // In syms_of_...
> DEFSYM (Qface_attribute, "face-attribyte");
> DEFSYM (Qregion, "region");
> DEFSYM (QCbackground, ":background");
> DEFSYM (Qdefault, "default");
> 
> // Calling
> Lisp_Object o = CALLN (Ffuncall, Qface_attribute, Qregion, QCbackground, Fselected_frame (), Qdefault);



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
@ 2017-09-26 22:11 Keith David Bershatsky
  2017-09-29 20:33 ` Philipp Stephani
  0 siblings, 1 reply; 14+ messages in thread
From: Keith David Bershatsky @ 2017-09-26 22:11 UTC (permalink / raw)
  To: emacs-devel; +Cc: Philipp Stephani

Here is a first draft of the conversion from Lisp to C.  It has everything (I think?) except for the `condition-case` statement, because I haven't learned how to do that yet in C.  If anyone sees an error, or if anyone could teach me how to properly incorporate the missing `condition_case` statement in `mc-face-attribute`, that would be greatly appreciated.

DEFUN ("mc-face-attribute", Fmc_face_attribute, Smc_face_attribute, 2, 4, 0,
       doc: /* Return the value of FACE's ATTRIBUTE on FRAME.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
If INHERIT is nil, only attributes directly defined by FACE are considered,
  so the return value may be `unspecified', or a relative value.
If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
  faces specified by its `:inherit' attribute; however the return value
  may still be `unspecified' or relative.
If INHERIT is a face or a list of faces, then the result is further merged
  with that face (or faces), until it becomes specified and absolute.
To ensure that the return value is always specified and absolute, use a
value of `default' for INHERIT; this will resolve any unspecified or
relative values by merging with the `default' face (which is always
completely specified). */)
     (Lisp_Object face, Lisp_Object attribute, Lisp_Object frame, Lisp_Object inherit)
{
/*
  (let ((value (internal-get-lisp-face-attribute face attribute frame)))
    (when (and inherit (face-attribute-relative-p attribute value))
      (let ((inh-from (mc-face-attribute face :inherit frame)))
        (unless (or (null inh-from) (eq inh-from 'unspecified))
          (condition-case nil
              (setq value
                    (mc-face-attribute-merged-with attribute value inh-from frame))
            (error nil)))))
    (when (and inherit
               (not (eq inherit t))
               (face-attribute-relative-p attribute value))
      (setq value (mc-face-attribute-merged-with attribute value inherit frame)))
    value)
*/
  Lisp_Object value = Finternal_get_lisp_face_attribute (face, attribute, frame);
  if (!EQ (inherit, Qnil)
      && EQ (Fface_attribute_relative_p (attribute, value), Qt))
    {
      Lisp_Object inh_from = Fmc_face_attribute (face, intern (":inherit"), frame, Qnil);
      if (!EQ (inh_from, Qnil)
          && !EQ (inh_from, intern ("unspecified")))
        /* FIXME:  learn how to use `Fcondition_case' here! */
        value = Fmc_face_attribute_merged_with (attribute, value, inh_from, frame);
    }
  if (!EQ (inherit, Qnil)
      && !EQ (inherit, Qt)
      && EQ (Fface_attribute_relative_p (attribute, value), Qt))
    value = Fmc_face_attribute_merged_with (attribute, value, inherit, frame);
  return value;
}

DEFUN ("mc-face-attribute-merged-with", Fmc_face_attribute_merged_with, Smc_face_attribute_merged_with, 3, 4, 0,
       doc: /* Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
FACES may be either a single face or a list of faces.
[This is an internal function.] */)
     (Lisp_Object attribute, Lisp_Object value, Lisp_Object faces, Lisp_Object frame)
{
/*
  (cond
    ((not (face-attribute-relative-p attribute value))
       value)
    ((null faces)
       value)
    ((consp faces)
      (mc-face-attribute-merged-with
        attribute
        (mc-face-attribute-merged-with attribute value (car faces) frame)
        (cdr faces)
        frame))
    (t
      (merge-face-attribute attribute value (mc-face-attribute faces attribute frame t))))
*/
  if (EQ (Fface_attribute_relative_p (attribute, value), Qnil))
    return value;
  if (EQ (faces, Qnil))
    return value;
  if (CONSP (faces))
    return Fmc_face_attribute_merged_with (attribute,
                                           Fmc_face_attribute_merged_with (attribute, value, XCAR (faces), frame),
                                           XCDR (faces),
                                           frame);
  return Fmerge_face_attribute (attribute,
                                value,
                                Fmc_face_attribute (faces, attribute, frame, Qt));
}



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
  2017-09-26  4:38 Keith David Bershatsky
  2017-09-26 18:46 ` Philipp Stephani
@ 2017-09-26 23:19 ` YAMAMOTO Mitsuharu
  1 sibling, 0 replies; 14+ messages in thread
From: YAMAMOTO Mitsuharu @ 2017-09-26 23:19 UTC (permalink / raw)
  To: Keith David Bershatsky; +Cc: Emacs Devel

>>>>> On Mon, 25 Sep 2017 21:38:07 -0700, Keith David Bershatsky <esq@lawlist.com> said:

> I am working on implementing my own feature requests to draw crosshairs (#17684) using multiple fake cursors (#22873), and I am trying to quickly convert (in C) the :background of the region face into a string -- e.g., "blue" or "#0000FF".  My goal is to do all of this in C, and I would like to avoid porting (rewriting) several Lisp functions to give me the result of:
>     (face-attribute 'region :background (selected-frame) 'default)

> Is there anything built-in into the Emacs C code base that already does this, or *almost* does this ...?

> BACKGROUND:  I already have a function written in C that converts a color string (e.g., "blue" or "#0000FF") into an LSL color vector, which is used by the new multiple fake cursors (#22873) feature.  I erase glyphless (floating) fake cursors by drawing new ones that match the background face.  When a region is active, I need the LSL color vector of the region :background.

Do you need xterm.c-level drawing functions?  Then perhaps you want
GCs rather than the color strings.  In the Mac port, I use the
following function.

/* Return GC for the face with FACE_ID on frame F.  If the face is not
   available, return DEFAULT_GC.  */

GC
mac_gc_for_face_id (struct frame *f, int face_id, GC default_gc)
{
  struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);

  if (face)
    {
      prepare_face_for_display (f, face);
      return face->gc;
    }
  else
    return default_gc;
}


Here's an example:

/* Draw a window divider from (x0,y0) to (x1,y1)  */

static void
mac_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1)
{
  struct frame *f = XFRAME (WINDOW_FRAME (w));
  GC gc = mac_gc_for_face_id (f, WINDOW_DIVIDER_FACE_ID,
			      f->output_data.mac->normal_gc);

  if ((y1 - y0 > x1 - x0 && x1 - x0 > 2)
      || (x1 - x0 > y1 - y0 && y1 - y0 > 3))
    {
      GC gc_first = mac_gc_for_face_id (f, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID,
					f->output_data.mac->normal_gc);
      GC gc_last = mac_gc_for_face_id (f, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID,
				       f->output_data.mac->normal_gc);

      if (y1 - y0 > x1 - x0)
	/* Vertical.  */
	{
	  mac_fill_rectangle (f, gc_first, x0, y0, 1, y1 - y0);
	  mac_fill_rectangle (f, gc, x0 + 1, y0, x1 - x0 - 2, y1 - y0);
	  mac_fill_rectangle (f, gc_last, x1 - 1, y0, 1, y1 - y0);
	}
      else
	/* Horizontal.  */
	{
	  mac_fill_rectangle (f, gc_first, x0, y0, x1 - x0, 1);
	  mac_fill_rectangle (f, gc, x0, y0 + 1, x1 - x0, y1 - y0 - 2);
	  mac_fill_rectangle (f, gc_last, x0, y1 - 1, x1 - x0, 1);
	}
    }
  else
    mac_fill_rectangle (f, gc, x0, y0, x1 - x0, y1 - y0);
}

				     YAMAMOTO Mitsuharu
				mituharu@math.s.chiba-u.ac.jp



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
@ 2017-09-27  0:24 Keith David Bershatsky
  2017-09-27  5:58 ` YAMAMOTO Mitsuharu
  0 siblings, 1 reply; 14+ messages in thread
From: Keith David Bershatsky @ 2017-09-27  0:24 UTC (permalink / raw)
  To: YAMAMOTO Mitsuharu; +Cc: emacs-devel

Thank you, YAMAMOTO Mitsuharu, for the example functions `mac_gc_for_face_id` and `mac_draw_window_divider'.  I do indeed use a couple of sections in xterm.c to draw multiple fake cursors (#22873) and crosshairs (#17684) when Emacs is built `--with-x` on OSX.  The current design passes the LSL color vector to `x_draw_window_cursor'.  I then multiply each color (red/green/blue) by 65535 and pass that along to `x_make_truecolor_pixel`.  Depending upon the `cursor_type`, I hijack either `f->output_data.x->cursor_pixel` or `f->output_data.x->cursor_gc' and I borrow the functionality of `x_make_gc`.

I am still implementing the new features for the GUI version of Emacs built `--with-ns` and have not yet done any testing to see whether I can draw/erase glyphless (floating) fake cursors in an Emacs build `--with-x` for X11 and/or on an Emacs for Windows build.  It works well `--with-ns`.  Essentially, I draw just the cursors and suppress the creation of glyphs when calling `draw_window_cursor` (which becomes `ns_draw_window_cursor') -- i.e., I suppress the call to `draw_phys_cursor_glyph`.  I am hoping that the Emacs builds for X11 and Windows will permit a similar design -- i.e., just draw a floating fake cursor in certain areas of the visible window that do not have any text.

To erase the floating glyphless fake cursors (with no text), I draw the shape of the cursor using the current background color.  The current design is to get everything into the LSL color vector, and then treat it differently once I get over to nsterm.m, w32term.c, or xterm.c depending upon the Emacs build.  In terms of the active region face, I needed to get the LSL equivalent for the region background.  Today, I ported from Lisp to C the functions `face-attribute` and `face-attribute-merged-with` which gets me the color string:

https://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00917.html

I use the following function to convert the color string to an LSL color vector:

mc_color_vector_calculate (struct window *w, Lisp_Object color)
{
  Lisp_Object target_frame = w->frame;
  Lisp_Object color_values;
  double valmax = XINT (XCAR (Fxw_color_values (build_string ("#ffffff"), target_frame)));
  Lisp_Object vlist;
  ptrdiff_t x;
  int i = 0;
  Lisp_Object temp = Qnil;
  Lisp_Object vector = (Fmake_vector (make_number (3), Qnil));
  if (!NILP (Fmemq ((Fframep (target_frame)), listn (CONSTYPE_HEAP, 3, Qx, Qw32, Qns))))
    {
      color_values = (Fxw_color_values (color, target_frame));
      for (vlist = color_values;
           CONSP (vlist);
           vlist = XCDR (vlist))
        {
          x = XINT (XCAR (vlist));
          temp = make_float (x / valmax);
          ASET (vector, i, temp);
          i = i + 1;
        }
    }
  return vector;

I will study your example functions (`mac_gc_for_face_id` and `mac_draw_window_divider') further and see if I can incorporate certain aspects into Emacs `--with-x` with respect to the new features that I am developing.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [09-26-2017 16:19:29] <27 Sep 2017 08:19:29 +0900>
FROM:  YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
> 
>  * * *
> 
> Do you need xterm.c-level drawing functions?  Then perhaps you want
> GCs rather than the color strings.  In the Mac port, I use the
> following function.
> 
> * * *



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
  2017-09-27  0:24 Keith David Bershatsky
@ 2017-09-27  5:58 ` YAMAMOTO Mitsuharu
  0 siblings, 0 replies; 14+ messages in thread
From: YAMAMOTO Mitsuharu @ 2017-09-27  5:58 UTC (permalink / raw)
  To: Keith David Bershatsky; +Cc: emacs-devel

>>>>> On Tue, 26 Sep 2017 17:24:44 -0700, Keith David Bershatsky <esq@lawlist.com> said:

> To erase the floating glyphless fake cursors (with no text), I draw the shape of the cursor using the current background color.  The current design is to get everything into the LSL color vector, and then treat it differently once I get over to nsterm.m, w32term.c, or xterm.c depending upon the Emacs build.  In terms of the active region face, I needed to get the LSL equivalent for the region background.  Today, I ported from Lisp to C the functions `face-attribute` and `face-attribute-merged-with` which gets me the color string:

That doesn't sound like a good design.  I think you should always use
faces to specify/retrieve colors so we can consistently utilize
existing infrastructure such as frame-wise themes.

Erasing cursors would be possible by calling `draw_glyphs' just as
`expose_area' does (it might be the case that you have to fill with
the frame background color beforehand).

Also, be sure to draw cursors/crosshairs on expose_frame while they
are active.  Otherwise they become invisible when we hide and then
show a frame, for example.

			     YAMAMOTO Mitsuharu
			mituharu@math.s.chiba-u.ac.jp



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
  2017-09-26 18:38 Keith David Bershatsky
@ 2017-09-29 13:25 ` Eli Zaretskii
  0 siblings, 0 replies; 14+ messages in thread
From: Eli Zaretskii @ 2017-09-29 13:25 UTC (permalink / raw)
  To: Keith David Bershatsky; +Cc: emacs-devel

> Date: Tue, 26 Sep 2017 11:38:03 -0700
> From: Keith David Bershatsky <esq@lawlist.com>
> 
> I have begun porting the two relevant Lisp functions to C and will submit them (when finished) in conjunction with the next draft of implementing my feature requests for crosshairs (#17684) and multiple fake cursors (#22873).  I may end up needing some help with some portions of the conversion, but it does not look as difficult as I had initially thought.

Thanks, but why would we want to port them to C?  is something wrong
with their current Lisp implementations?




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
  2017-09-26 22:11 Keith David Bershatsky
@ 2017-09-29 20:33 ` Philipp Stephani
  0 siblings, 0 replies; 14+ messages in thread
From: Philipp Stephani @ 2017-09-29 20:33 UTC (permalink / raw)
  To: Keith David Bershatsky, emacs-devel

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

Keith David Bershatsky <esq@lawlist.com> schrieb am Mi., 27. Sep. 2017 um
00:11 Uhr:

> Here is a first draft of the conversion from Lisp to C.  It has everything
> (I think?) except for the `condition-case` statement, because I haven't
> learned how to do that yet in C.
>

There's a family of functions name "internal_condition_case..." that are
the C equivalents to the `condition-case' special form.

[-- Attachment #2: Type: text/html, Size: 694 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
@ 2017-10-05  0:24 Keith David Bershatsky
  2017-10-05  6:47 ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Keith David Bershatsky @ 2017-10-05  0:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Thank you, Eli, for looking at this particular thread.  The first draft of crosshairs is taking me longer than I had initially anticipated, and I still have not played with implementing that functionality for Emacs flavors W32 or X11.  So, it may be awhile before I have a draft ready.  In the meantime, I ported from Lisp to C the functions `face-attribute` (except the condition-case) and `face-attribute-merged-with':

https://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00917.html

My preference is that multiple fake cursors and crosshairs be implemented entirely in C, with just a little bit of Lisp to access those tools.  I also felt that relying on Lisp might somehow slow things down a bit, and speed is really important.

If you or anyone is interested in adding `face-attribute` and `face-attribute-merged-with' to xfaces.c, the link above has my suggested implementation.

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [09-29-2017 06:25:38] <29 Sep 2017 16:25:38 +0300>
FROM:  Eli Zaretskii <eliz@gnu.org>
> 
>  * * *
> 
> > Date: Tue, 26 Sep 2017 11:38:03 -0700
> > From: Keith David Bershatsky <esq@lawlist.com>
> > 
> > I have begun porting the two relevant Lisp functions to C and will submit them (when finished) in conjunction with the next draft of implementing my feature requests for crosshairs (#17684) and multiple fake cursors (#22873).  . . .
> 
> Thanks, but why would we want to port them to C?  is something wrong
> with their current Lisp implementations?



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
  2017-10-05  0:24 C equivalent for: (face-attribute 'region :background (selected-frame) 'default) Keith David Bershatsky
@ 2017-10-05  6:47 ` Eli Zaretskii
  2017-10-05  7:11   ` YAMAMOTO Mitsuharu
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2017-10-05  6:47 UTC (permalink / raw)
  To: Keith David Bershatsky; +Cc: emacs-devel

> Date:  Wed, 04 Oct 2017 17:24:50 -0700
> From:  Keith David Bershatsky <esq@lawlist.com>
> Cc:  emacs-devel@gnu.org
> 
> My preference is that multiple fake cursors and crosshairs be implemented entirely in C, with just a little bit of Lisp to access those tools.  I also felt that relying on Lisp might somehow slow things down a bit, and speed is really important.

I don't think you will gain speed by moving these functions to C,
because their slow part is already implemented in C.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
  2017-10-05  6:47 ` Eli Zaretskii
@ 2017-10-05  7:11   ` YAMAMOTO Mitsuharu
  0 siblings, 0 replies; 14+ messages in thread
From: YAMAMOTO Mitsuharu @ 2017-10-05  7:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Keith David Bershatsky, emacs-devel

>>>>> On Thu, 05 Oct 2017 09:47:15 +0300, Eli Zaretskii <eliz@gnu.org> said:

>> Date: Wed, 04 Oct 2017 17:24:50 -0700 From: Keith David Bershatsky
>> <esq@lawlist.com> Cc: emacs-devel@gnu.org
>> 
>> My preference is that multiple fake cursors and crosshairs be
>> implemented entirely in C, with just a little bit of Lisp to access
>> those tools.  I also felt that relying on Lisp might somehow slow
>> things down a bit, and speed is really important.

> I don't think you will gain speed by moving these functions to C,
> because their slow part is already implemented in C.

And as I already commented, creating LSL vector or something from a
face in a platform-independent code is not a good design in the sense
that it is inconsistent with the current code.  Each drawing backend
can get color information (as GC, in all the platforms other than NS)
from a given face as I showed in the code `mac_gc_for_face_id'.

Also, erasing crosshairs or cursors could be done by imitating the
code in `expose_area'.  I think you don't need to know which face is
used in the erased area.

				     YAMAMOTO Mitsuharu
				mituharu@math.s.chiba-u.ac.jp



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
@ 2017-10-06  3:53 Keith David Bershatsky
  0 siblings, 0 replies; 14+ messages in thread
From: Keith David Bershatsky @ 2017-10-06  3:53 UTC (permalink / raw)
  To: YAMAMOTO Mitsuharu; +Cc: emacs-devel

Thank you, YAMAMOTO Mitsuharu, for following this thread.

Emacs for all three platforms already uses (to some extent) LSL color vectors.  nsterm.m does not need to convert the LSL values and it uses them liberally.  xterm.c multiplies or divides them by 65535 depending upon which direction the conversion is needed.  w32term.c multiplies them by 255.

My current design erases fake cursors in the reverse method in which they were drawn.  A fake cursor with a glyph (e.g., text underneath) needs no special treatment -- i.e., erase_phys_cursor takes care of everything (given the proper configuration).  A floating glyphless cursor (with no text) can be used to create a floating horizontal or vertical line anywhere within the window-body-height/width -- it is erased by drawing it again with the background color.

Inasmuch as we can convert to/from any color format we desire, what happens internally is just a matter of personal preference.  The draft API for fake cursors already supports three formats:  "red", [1.0 0.0 0.0], and "#FF0000".  The API can easily be extended to support a face, which only the background color would be relevant.  The user does not need to care about the fact that Emacs is converting from:  red-face => red => [1 0 0] => xterm.c/nsterm.m/w32term.c compatible implementations.

I successfully implemented a working draft of crosshairs in xterm.c today, and am now moving on to w32 in the coming days.

Extracting the coordinates for fake cursors when dealing with overlays and text properties will be last on my list of things to do, since that is the most intimidating.

Implementing functionality similar to Magnars multiple cursors library will be left to someone more advanced than myself.  For the past several months, I have been using built-in multiple fake cursors in conjunction with Magnars' library -- i.e., instead of a box overlay, I'm using a vertical bar fake cursor for each fake cursor.

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [10-05-2017 00:11:44] <05 Oct 2017 16:11:44 +0900>
FROM:  YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
> 
>  * * *
> 
> And as I already commented, creating LSL vector or something from a
> face in a platform-independent code is not a good design in the sense
> that it is inconsistent with the current code.  Each drawing backend
> can get color information (as GC, in all the platforms other than NS)
> from a given face as I showed in the code `mac_gc_for_face_id'.
> 
> Also, erasing crosshairs or cursors could be done by imitating the
> code in `expose_area'.  I think you don't need to know which face is
> used in the erased area.
> 
>          YAMAMOTO Mitsuharu
>     mituharu@math.s.chiba-u.ac.jp



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-10-06  3:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-05  0:24 C equivalent for: (face-attribute 'region :background (selected-frame) 'default) Keith David Bershatsky
2017-10-05  6:47 ` Eli Zaretskii
2017-10-05  7:11   ` YAMAMOTO Mitsuharu
  -- strict thread matches above, loose matches on Subject: below --
2017-10-06  3:53 Keith David Bershatsky
2017-09-27  0:24 Keith David Bershatsky
2017-09-27  5:58 ` YAMAMOTO Mitsuharu
2017-09-26 22:11 Keith David Bershatsky
2017-09-29 20:33 ` Philipp Stephani
2017-09-26 22:06 Keith David Bershatsky
2017-09-26 18:38 Keith David Bershatsky
2017-09-29 13:25 ` Eli Zaretskii
2017-09-26  4:38 Keith David Bershatsky
2017-09-26 18:46 ` Philipp Stephani
2017-09-26 23:19 ` YAMAMOTO Mitsuharu

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).