all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Keith David Bershatsky <esq@lawlist.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Obtain X / HPOS with move_it_to at eol when buffer-display-table	line-feed
Date: Tue, 29 Aug 2017 11:51:07 -0700	[thread overview]
Message-ID: <m24lsq8axw.wl%esq@lawlist.com> (raw)

Thank you, Eli, for looking at this particular thread.

I am creating pilcrows at the end of each line using the following code:

(let ((face (face-id 'font-lock-warning-face)))
  (aset (or buffer-display-table
            (setq buffer-display-table (make-display-table))) ?\n `[(182 . ,face) ?\n]))

Using POS, I would like to obtain X/Y/HPOS/VPOS for any particular eol pilcrow.  If I search for POS at the end of the line using move_it_to, then it.current_x and it.current_hpos are not the values that I need.  In that situation, I have to subtract frame-char-width from it.current_x, and I have to subtract 1 from it.current_hpos.  it.current_x and it.current_hpos are essentially off to a tune of one character to the right of the pilcrow.

I would like to come up with a more sophisticated test for when IT is at the end of the line looking at a pilcrow as described above, and when that situation exists, then return the X and HPOS to the left of the pilcrow (instead of to the right of the pilcrow).  [I am then going to place a fake cursor on the pilcrow, which is beyond the scope of the current issue.]

Lisp_Object
get_x_y_hpos_vpos (struct window *w, ptrdiff_t start, ptrdiff_t position)
{
  struct it it;
  void *itdata = bidi_shelve_cache ();
  struct text_pos start_text_position;
  int x, y, hpos, vpos;
  struct frame *f = XFRAME (w->frame);
  int frame_char_width = FRAME_COLUMN_WIDTH (f);
  ptrdiff_t pt_original = PT;
  ptrdiff_t pt_byte_original = PT_BYTE;
  /* marker_position (w->start) is NOT reliable here. */
  if (position >= start)
    {
      SET_TEXT_POS_FROM_MARKER (start_text_position, w->start);
      start_display (&it, w, start_text_position);
      /* Move IT to POSINT, but no farther than the lower right-hand corner of the visible window. */
      move_it_to (&it, position, it.last_visible_x, it.last_visible_y - 1, -1, MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y);
      if (IT_CHARPOS (it) != position)
        goto done;
      y = it.current_y;
      if (WINDOW_HEADER_LINE_HEIGHT (w) > 0)
        vpos = it.vpos + 1;
        else
          vpos = it.vpos;
      if (FETCH_BYTE (IT_BYTEPOS (it)) == '\n'
          /* && (aref buffer-display-table ?\n) == [(182 . 127) 10] */
          )
        {
          x = it.current_x - frame_char_width;
          hpos = it.hpos - 1;
        }
        else
          {
            x = it.current_x;
            hpos = it.hpos;
          }
    }
    else
      {
        done:
        x = -1;
        y = -1;
        hpos = -1;
        vpos = -1;
      }
  bidi_unshelve_cache (itdata, false);
  return listn (CONSTYPE_HEAP, 4, make_number (x), make_number (y), make_number (hpos), make_number (vpos));
}



             reply	other threads:[~2017-08-29 18:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29 18:51 Keith David Bershatsky [this message]
2017-08-30 16:51 ` Obtain X / HPOS with move_it_to at eol when buffer-display-table line-feed Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2017-08-31 16:07 Keith David Bershatsky
2017-08-31 16:17 ` Eli Zaretskii
2017-08-30 18:35 Keith David Bershatsky
2017-08-30 19:03 ` Eli Zaretskii
2017-08-29  7:01 Keith David Bershatsky
2017-08-29 14:59 ` Eli Zaretskii

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=m24lsq8axw.wl%esq@lawlist.com \
    --to=esq@lawlist.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /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.