texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[6403] underlining of references


From: Gavin D. Smith
Subject: [6403] underlining of references
Date: Fri, 10 Jul 2015 23:16:21 +0000

Revision: 6403
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6403
Author:   gavin
Date:     2015-07-10 23:16:20 +0000 (Fri, 10 Jul 2015)
Log Message:
-----------
underlining of references

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/display.c
    trunk/info/info-utils.c
    trunk/info/infodoc.c
    trunk/info/nodemenu.c
    trunk/info/terminal.c
    trunk/info/terminal.h
    trunk/info/variables.c
    trunk/info/variables.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2015-07-07 18:24:28 UTC (rev 6402)
+++ trunk/ChangeLog     2015-07-10 23:16:20 UTC (rev 6403)
@@ -1,3 +1,26 @@
+2015-07-10  Gavin Smith  <address@hidden>
+
+       * info/variables.c (info_variables): New user variable 
+       'xref-rendition'.
+       * info/display.c (xref_rendition_p): New variable.
+       * info/terminal.c (terminal_begin_underline, terminal_end_underline):
+       New functions.
+
+       * info/info-utils.c (scan_reference_label): Don't place terminal 
+       escape characters in text of node.  Alter expression used for 
+       end of a label.
+
+       * info/display.c (decide_if_in_reference): New function, based
+       on decide_if_in_match.
+       (display_update_window_1): Keep track of whether we are in a 
+       cross-reference or menu item and turn on and off underlining 
+       accordingly, if xref-rendition=On.
+
+       * info/info-utils.c (printed_rep),
+       * info/infodoc.c (pretty_keyseq),
+       * info/nodemenu.c (format_node_info): Use { 0 } for null struct 
+       initializer instead of {}.
+
 2015-07-07  Gavin Smith  <address@hidden>
 
        * tp/Texinfo/Convert/Line.pm,

Modified: trunk/info/display.c
===================================================================
--- trunk/info/display.c        2015-07-07 18:24:28 UTC (rev 6402)
+++ trunk/info/display.c        2015-07-10 23:16:20 UTC (rev 6403)
@@ -225,8 +225,13 @@
 }
 
 
+/* User variable to control whether matches from a search are highlighted. */
 int highlight_searches_p = 0;
 
+/* Controls whether cross-references and menu entries are underlined.
+   TODO: have a choice of different styles and colours. */
+int xref_rendition_p = 0;
+
 /* Given an array MATCHES with regions, and an offset *MATCH_INDEX, decide
    if we are inside a region at offset OFF.  The matches are assumed not
    to overlap and to be in order. */
@@ -254,6 +259,31 @@
   *in_match = m;
 }
 
+/* Similar to decide_if_in_match, but used for reference highlighting. */
+static void
+decide_if_in_reference (long off, int *in_ref, REFERENCE **references,
+                        int *ref_index)
+{
+  int i = *ref_index;
+  int m = *in_ref;
+
+  for (; (references[i]); i++)
+    {
+      if (references[i]->start > off)
+        break;
+
+      m = 1;
+
+      if (references[i]->end > off)
+        break;
+
+      m = 0;
+    }
+
+  *ref_index = i;
+  *in_ref = m;
+}
+
 /* Print each line in the window into our local buffer, and then
    check the contents of that buffer against the display.  If they
    differ, update the display.
@@ -277,9 +307,20 @@
   size_t match_index = 0;
   int in_match = 0; /* If we have highlighting on for a match. */
 
+  REFERENCE **refs = 0;
+  int ref_index = 0, in_ref = 0;
+  int ref_seen_in_line = 0;
+
+  /* Set to 1 when we are in the text of a cross-reference and at the start of 
+     a new line, and haven't seen a non-whitespace character yet. */
+  int ref_leading_whitespace = 0;
+
   if (highlight_searches_p)
     matches = win->matches;
 
+  if (xref_rendition_p)
+    refs = win->node->references;
+
   /* Find first search match after the start of the page, and check whether
      we start inside a match. */
   if (matches)
@@ -289,6 +330,15 @@
                           matches, win->match_count, &match_index);
     }
 
+  /* Likewise, check whether we start within a cross-reference or menu 
+     entry.  */
+  if (refs)
+    {
+      ref_index = 0;
+      decide_if_in_reference (win->line_starts[win->pagetop], &in_ref,
+                              refs, &ref_index);
+    }
+
   text_buffer_init (&tb_printed_line);
 
   if (in_match)
@@ -298,6 +348,13 @@
       terminal_goto_xy (0, win->first_row);
     }
 
+  if (in_ref)
+    {
+      terminal_begin_underline ();
+      ref_seen_in_line = 1;
+      terminal_goto_xy (0, win->first_row);
+    }
+
   for (mbi_init (iter, start, 
                  win->node->contents + win->node->nodelen - start);
        mbi_avail (iter);
@@ -323,6 +380,11 @@
       rep = printed_representation (&iter, &delim, pl_chars, &pchars, &pbytes);
 
       cur_ptr = mbi_cur_ptr (iter);
+      if (ref_leading_whitespace && !strchr (" \t", *cur_ptr))
+        {
+          ref_leading_whitespace = 0;
+          terminal_begin_underline ();
+        }
 
       if (matches && match_index != win->match_count)
         {
@@ -341,23 +403,56 @@
                 {
                   match_seen_in_line = 1;
 
-                  /* Output the line so far. */
-                  terminal_goto_xy (0, win->first_row + pl_num);
-                  terminal_write_chars (text_buffer_base (&tb_printed_line),
-                                      text_buffer_off (&tb_printed_line));
+                  if (!ref_seen_in_line)
+                    {
+                      /* Output the line so far. */
+                      terminal_goto_xy (0, win->first_row + pl_num);
+                      terminal_write_chars
+                                        (text_buffer_base (&tb_printed_line),
+                                         text_buffer_off (&tb_printed_line));
+                    }
                 }
               terminal_begin_standout ();
             }
         }
 
+      if (refs && refs[ref_index])
+        {
+          int was_in_ref = in_ref;
+          decide_if_in_reference (cur_ptr - win->node->contents,
+                                  &in_ref, refs, &ref_index);
+
+          if (was_in_ref && !in_ref)
+            {
+              ref_leading_whitespace = 0;
+              terminal_end_underline ();
+            }
+          else if (!was_in_ref && in_ref)
+            {
+              if (!ref_seen_in_line)
+                {
+                  ref_seen_in_line = 1;
+
+                  if (!match_seen_in_line)
+                    {
+                      /* Output the line so far. */
+                      terminal_goto_xy (0, win->first_row + pl_num);
+                      terminal_write_chars
+                                        (text_buffer_base (&tb_printed_line),
+                                         text_buffer_off (&tb_printed_line));
+                    }
+                }
+              terminal_begin_underline ();
+            }
+        }
+
+      /* If a newline character has been seen, or we have reached the
+         edge of the display.  */
       if (delim || pl_chars + pchars >= win->width)
         {
-          /* If this character cannot be printed in this line, we have
-             found the end of this line as it would appear on the screen. */
-
           text_buffer_add_char (&tb_printed_line, '\0');
 
-          if (!match_seen_in_line)
+          if (!match_seen_in_line && !ref_seen_in_line)
             {
               finish = display_node_text (win->first_row + pl_num,
                           text_buffer_base (&tb_printed_line),
@@ -372,8 +467,8 @@
             }
 
           /* Check if a line continuation character should be displayed.
-             Don't print one if printing the last character in this window 
-             could possibly cause the screen to scroll. */
+             Don't print one on the very last line of the display as this 
could 
+             cause scrolling. */
           if (!delim && 1 + pl_num + win->first_row < the_screen->height)
             {
               terminal_goto_xy (win->width - 1, win->first_row + pl_num);
@@ -396,18 +491,33 @@
                   if (matches)
                     {
                       /* Check if the next line starts in a match. */
-                      decide_if_in_match (mbi_cur_ptr (iter) - 
win->node->contents,
-                                          &in_match, matches, win->match_count,
-                                          &match_index);
+                      decide_if_in_match
+                                   (mbi_cur_ptr (iter) - win->node->contents,
+                                    &in_match, matches, win->match_count,
+                                    &match_index);
                       if (!in_match)
                         terminal_end_standout ();
                     }
+
+                  if (refs)
+                    {
+                      if (in_ref)
+                        terminal_end_underline ();
+
+                      /* Check if the next line starts in a match. */
+                      decide_if_in_reference
+                                   (mbi_cur_ptr (iter) - win->node->contents,
+                                    &in_ref, refs, &ref_index);
+                    }
                 }
               fflush (stdout);
             }
 
           /* Set for next line. */
-          match_seen_in_line = in_match ? 1 : 0;
+          match_seen_in_line = in_match;
+          ref_seen_in_line = in_ref;
+          ref_leading_whitespace = in_ref;
+          terminal_end_underline ();
           ++pl_num;
 
           pl_chars = 0;
@@ -418,13 +528,13 @@
 
           /* Go to the start of the next line if we are outputting in this
              function. */
-          if (match_seen_in_line)
+          if (match_seen_in_line || ref_seen_in_line)
             terminal_goto_xy (0, win->first_row + pl_num);
         }
 
       if (*cur_ptr != '\n' && rep) 
         {
-          if (!match_seen_in_line)
+          if (!match_seen_in_line && !ref_seen_in_line)
             text_buffer_add_string (&tb_printed_line, rep, pbytes);
           else
             terminal_write_chars (rep, pbytes);
@@ -435,7 +545,7 @@
     }
 
   /* This would be the very last line of the node. */
-  if (pl_chars && !match_seen_in_line)
+  if (pl_chars && !match_seen_in_line && !ref_seen_in_line)
     {
       text_buffer_add_char (&tb_printed_line, '\0');
       display_node_text (win->first_row + pl_num,
@@ -448,6 +558,11 @@
   if (in_match)
     terminal_end_standout ();
 
+  /* Unlike search match highlighting, we always turn reference highlighting
+     off at the end of each line. */
+  /*if (in_ref)
+    terminal_end_underline (); */
+
   text_buffer_free (&tb_printed_line);
   return pl_num;
 }

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2015-07-07 18:24:28 UTC (rev 6402)
+++ trunk/info/info-utils.c     2015-07-10 23:16:20 UTC (rev 6403)
@@ -489,13 +489,14 @@
   return 0;
 }
 
-static struct text_buffer printed_rep = {}; /* Initialize with all zeroes. */
+static struct text_buffer printed_rep = { 0 };
 
 /* Return pointer to string that is the printed representation of character
    (or other logical unit) at ITER if it were printed at screen column
-   PL_CHARS.  Use ITER_SETBYTES (info-utils.h) on ITER if byte length is
-   different.  If ITER points at an end-of-line character, set *DELIM to this
-   character.  *PCHARS gets the number of screen columns taken up by
+   PL_CHARS.  Use ITER_SETBYTES (info-utils.h) on ITER if we need to advance 
+   past a unit that the multibyte iteractor doesn't know about (like an ANSI 
+   escape sequence).  If ITER points at an end-of-line character, set *DELIM 
to 
+   this character.  *PCHARS gets the number of screen columns taken up by
    outputting the return value, and *PBYTES the number of bytes in returned
    string.  Return value is not null-terminated.  Return value must not be
    freed by caller. */
@@ -612,8 +613,12 @@
 /* Whether contents of nodes should be rewritten. */
 static int rewrite_p;
 
-static char *input_start, *inptr;
+/* inptr is moved forward through the body of a node. */
+static char *inptr;
 
+/* Pointer to first byte of node (after node separator). */
+static char *input_start;
+
 /* Number of bytes in node contents. */
 static size_t input_length;
 
@@ -1090,6 +1095,7 @@
 static void
 underlining_off (void)
 {
+  return;
   write_extra_bytes_to_output (ANSI_UNDERLINING_OFF,
                                strlen (ANSI_UNDERLINING_OFF));
 }
@@ -1098,6 +1104,7 @@
 static void
 underlining_on (void)
 {
+  return;
   write_extra_bytes_to_output (ANSI_UNDERLINING_ON,
                                strlen (ANSI_UNDERLINING_ON));
 }
@@ -1297,7 +1304,6 @@
 static int
 scan_reference_label (REFERENCE *entry)
 {
-  char *nl_ptr;
   char *end;
   char *label = 0;
   long label_len;
@@ -1328,42 +1334,16 @@
 
   end = inptr + label_len;
 
-  underlining_on ();
-
-  /* Must start underlining first so that entry->start points to a printable
-     character.  Otherwise the cursor can end up in the previous column. */
   if (preprocess_nodes_p)
     entry->start = text_buffer_off (&output_buf);
 
-  /* Write text of label.  If there is a newline in the middle of
-     a reference label, turn off underlining until text starts again. */
-  while (inptr < end)
-    {
-      nl_ptr = strchr (inptr, '\n');
-      if (!nl_ptr || nl_ptr >= end)
-        break;
-
-      copy_input_to_output (nl_ptr - inptr);
-
-      /* Note we do this before the newline is output.  This way if
-         the first half of the label is on the bottom line of the
-         screen, underlining will not be left on. */
-      underlining_off ();
-
-      /* Output newline and any whitespace at start of next line. */
-      copy_input_to_output (1 + skip_whitespace (nl_ptr + 1));
-
-      underlining_on ();
-    }
-
-  /* Output rest of label */
+  /* Write text of label. */
   copy_input_to_output (end - inptr);
-  underlining_off ();
 
-  if (preprocess_nodes_p)
+  if (rewrite_p)
     entry->end = text_buffer_off (&output_buf);
   else
-    entry->end = entry->start + label_len;
+    entry->end = end - input_start;
 
 #ifdef QUOTE_NODENAMES
   if (inptr[0] == '\177')

Modified: trunk/info/infodoc.c
===================================================================
--- trunk/info/infodoc.c        2015-07-07 18:24:28 UTC (rev 6402)
+++ trunk/info/infodoc.c        2015-07-10 23:16:20 UTC (rev 6403)
@@ -606,7 +606,7 @@
 char *
 pretty_keyseq (int *keyseq)
 {
-  static struct text_buffer rep = {};
+  static struct text_buffer rep = { 0 };
 
   if (!text_buffer_base (&rep))
     text_buffer_init (&rep);

Modified: trunk/info/nodemenu.c
===================================================================
--- trunk/info/nodemenu.c       2015-07-07 18:24:28 UTC (rev 6402)
+++ trunk/info/nodemenu.c       2015-07-10 23:16:20 UTC (rev 6403)
@@ -52,7 +52,7 @@
 {
   register int i;
   char *containing_file;
-  static struct text_buffer line_buffer = {};
+  static struct text_buffer line_buffer = { 0 };
 
   if (!text_buffer_base (&line_buffer))
     text_buffer_init (&line_buffer);

Modified: trunk/info/terminal.c
===================================================================
--- trunk/info/terminal.c       2015-07-07 18:24:28 UTC (rev 6402)
+++ trunk/info/terminal.c       2015-07-10 23:16:20 UTC (rev 6403)
@@ -60,6 +60,8 @@
 VFunction *terminal_end_inverse_hook = NULL;
 VFunction *terminal_begin_standout_hook = NULL;
 VFunction *terminal_end_standout_hook = NULL;
+VFunction *terminal_begin_underline_hook = NULL;
+VFunction *terminal_end_underline_hook = NULL;
 VFunction *terminal_prep_terminal_hook = NULL;
 VFunction *terminal_unprep_terminal_hook = NULL;
 VFunction *terminal_up_line_hook = NULL;
@@ -127,6 +129,9 @@
 /* Strings entering and leaving standout mode. */
 char *term_so, *term_se;
 
+/* Strings entering and leaving underline mode. */
+char *term_us, *term_ue;
+
 /* Although I can't find any documentation that says this is supposed to
    return its argument, all the code I've looked at (termutils, less)
    does so, so fine.  */
@@ -395,6 +400,28 @@
     }
 }
 
+void
+terminal_begin_underline (void)
+{
+  if (terminal_begin_underline_hook)
+    (*terminal_begin_underline_hook) ();
+  else
+    {
+      send_to_terminal (term_us);
+    }
+}
+
+void
+terminal_end_underline (void)
+{
+  if (terminal_end_underline_hook)
+    (*terminal_end_underline_hook) ();
+  else
+    {
+      send_to_terminal (term_ue);
+    }
+}
+
 /* Ring the terminal bell.  The bell is run visibly if it both has one and
    terminal_use_visible_bell_p is non-zero. */
 void
@@ -823,6 +850,12 @@
   else
     term_se = NULL;
 
+  term_us = tgetstr ("us", &buffer);
+  if (term_us)
+    term_ue = tgetstr ("ue", &buffer);
+  else
+    term_ue = NULL;
+
   if (!term_cr)
     term_cr =  "\r";
 

Modified: trunk/info/terminal.h
===================================================================
--- trunk/info/terminal.h       2015-07-07 18:24:28 UTC (rev 6402)
+++ trunk/info/terminal.h       2015-07-10 23:16:20 UTC (rev 6403)
@@ -118,6 +118,12 @@
 extern void terminal_end_standout (void);
 extern VFunction *terminal_end_standout_hook;
 
+/* Turn on and off underline mode if possible. */
+void terminal_begin_underline (void);
+extern VFunction *terminal_begin_underline_hook;
+void terminal_end_underline (void);
+extern VFunction *terminal_end_underline_hook;
+
 /* Scroll an area of the terminal, starting with the region from START
    to END, AMOUNT lines.  If AMOUNT is negative, the lines are scrolled
    towards the top of the screen, else they are scrolled towards the

Modified: trunk/info/variables.c
===================================================================
--- trunk/info/variables.c      2015-07-07 18:24:28 UTC (rev 6402)
+++ trunk/info/variables.c      2015-07-10 23:16:20 UTC (rev 6403)
@@ -120,6 +120,10 @@
       N_("Highlight search matches"),
     &highlight_searches_p, (char **)on_off_choices },
 
+  { "xref-rendition",
+      N_("Underline cross-references and menu entries"),
+    &xref_rendition_p, (char **)on_off_choices },
+
   { "mouse",
       N_("Method to use to track mouse events"),
     &mouse_protocol, (char **)mouse_choices },

Modified: trunk/info/variables.h
===================================================================
--- trunk/info/variables.h      2015-07-07 18:24:28 UTC (rev 6402)
+++ trunk/info/variables.h      2015-07-10 23:16:20 UTC (rev 6403)
@@ -81,6 +81,7 @@
 extern int preprocess_nodes_p;
 extern int key_time;
 extern int highlight_searches_p;
+extern int xref_rendition_p;
 extern int mouse_protocol;
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]