all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Perry E. Metzger" <perry@piermont.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: cpitclaudel@gmail.com, monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: Advice needed on modeline customization hack...
Date: Mon, 17 Apr 2017 11:21:44 -0400	[thread overview]
Message-ID: <20170417112144.7de5cc4f@jabberwock.cb.piermont.com> (raw)
In-Reply-To: <20170417085326.1e3c4b30@jabberwock.cb.piermont.com>

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

Attached find new patches. I've made most of the changes requested,
with two small exceptions noted below:

On Mon, 17 Apr 2017 08:53:26 -0400 "Perry E. Metzger"
<perry@piermont.com> wrote:
> > I also think that using digits 0 and 1 is better than using the
> > words, but that's my personal preference, so if you feel strongly
> > about using words, I won't object.
>
> I'm used to the usual rule in English classes that one uses the
> written out words for small numbers, but this is technical
> documentation and I think I'll change it to the way you prefer.

So I read the surrounding documentation and docstrings, and it seems
that there is a consistent style, both in docstrings and in the
manuals, of saying "zero" and "one" rather than "0" and "1", so in
order to keep to the apparent style I will be leaving it as "zero" and
one".

I have made all your other proposed changes to the documentation.

I've renamed the variable column-number-indicator-zero-based as
suggested, though I'm wondering if we should say "display" instead of
"indicator" to match the documentation.

> > > +(defvar column-number-mode-starts-from-zero t
> > > +  "When set to true, Column Number mode displays columns
> > > starting from zero. +Otherwise, displayed column numbers start
> > > from one.")
> >
> > This should be a defcustom, not defvar.
>
> Easily fixed.

I've set it to :type 'boolean in :group 'mode-line (and have made all
your other proposed changes with one exception):

> > I think it's best to have
> > it in xdisp.c, where the feature is implemented, in which case you
> > should add the necessary stuff to cus-start.el to allow its
> > customization by Custom.
>
> I thought that since the rest of the lisp side was done there
> (including the minor mode) that it was better to have it in the .el
> file. Do you have a strong opinion?

Looking around, it seems that many such customization variables are in
simple.el already, and that there is a bias now towards putting code
into the lisp side and not the C side, so for now, my new patch leaves
it there.

Perry
-- 
Perry E. Metzger		perry@piermont.com

[-- Attachment #2: column.diff --]
[-- Type: application/octet-stream, Size: 9003 bytes --]

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index 1a9c65a08c..38ef917377 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -1327,13 +1327,19 @@ Optional Mode Line
 @cindex mode, Column Number
 @findex column-number-mode
   Similarly, you can display the current column number by turning on
-Column number mode with @kbd{M-x column-number-mode}.  The column
+Column Number mode with @kbd{M-x column-number-mode}.  The column
 number is indicated by the letter @samp{C}.  However, when both of
 these modes are enabled, the line and column numbers are displayed in
 parentheses, the line number first, rather than with @samp{L} and
 @samp{C}.  For example: @samp{(561,2)}.  @xref{Minor Modes}, for more
 information about minor modes and about how to use these commands.
 
+@vindex column-number-indicator-zero-based
+  In Column Number mode, the displayed column number counts from zero
+starting at the left margin of the window.  If you would prefer for
+the displayed column number to count from one, you may set
+@code{column-number-indicator-zero-based} to @code{nil}.
+
 @cindex narrowing, and line number display
   If you have narrowed the buffer (@pxref{Narrowing}), the displayed
 line number is relative to the accessible portion of the buffer.
diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi
index d6f014fada..bd2bacc739 100644
--- a/doc/lispref/frames.texi
+++ b/doc/lispref/frames.texi
@@ -1871,7 +1871,7 @@ Frame Titles
 This variable specifies how to compute a name for a frame when you have
 not explicitly specified one.  The variable's value is actually a mode
 line construct, just like @code{mode-line-format}, except that the
-@samp{%c} and @samp{%l} constructs are ignored.  @xref{Mode Line
+@samp{%c}, @samp{%C}, and @samp{%l} constructs are ignored.  @xref{Mode Line
 Data}.
 @end defvar
 
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 132dda3fc6..1303cb6caf 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -2093,7 +2093,12 @@ %-Constructs
 @xref{Buffer Names}.
 
 @item %c
-The current column number of point.
+The current column number of point, counting from zero starting at the
+left margin of the window.
+
+@item %C
+The current column number of point, counting from one starting at the
+left margin of the window.
 
 @item %e
 When Emacs is nearly out of memory for Lisp objects, a brief message
diff --git a/etc/refcards/gnus-logo.pdf b/etc/refcards/gnus-logo.pdf
deleted file mode 100644
index 3629a605e6..0000000000
Binary files a/etc/refcards/gnus-logo.pdf and /dev/null differ
diff --git a/lisp/bindings.el b/lisp/bindings.el
index f641865ba3..da90165ae1 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -368,12 +368,19 @@ mode-line-position
 mouse-1: Display Line and Column Mode Menu")))
     (line-number-mode
      ((column-number-mode
-       (10 ,(propertize
-	     " (%l,%c)"
-	     'local-map mode-line-column-line-number-mode-map
-	     'mouse-face 'mode-line-highlight
-	     'help-echo "Line number and Column number\n\
+       (column-number-indicator-zero-based
+        (10 ,(propertize
+              " (%l,%c)"
+              'local-map mode-line-column-line-number-mode-map
+              'mouse-face 'mode-line-highlight
+              'help-echo "Line number and Column number\n\
 mouse-1: Display Line and Column Mode Menu"))
+        (10 ,(propertize
+              " (%l,%C)"
+              'local-map mode-line-column-line-number-mode-map
+              'mouse-face 'mode-line-highlight
+              'help-echo "Line number and Column number\n\
+mouse-1: Display Line and Column Mode Menu")))
        (6 ,(propertize
 	    " L%l"
 	    'local-map mode-line-column-line-number-mode-map
@@ -381,12 +388,19 @@ mode-line-position
 	    'help-echo "Line Number\n\
 mouse-1: Display Line and Column Mode Menu"))))
      ((column-number-mode
-       (5 ,(propertize
-	    " C%c"
-	    'local-map mode-line-column-line-number-mode-map
-	    'mouse-face 'mode-line-highlight
-	    'help-echo "Column number\n\
-mouse-1: Display Line and Column Mode Menu"))))))
+       (column-number-indicator-zero-based
+        (5 ,(propertize
+             " C%c"
+             'local-map mode-line-column-line-number-mode-map
+             'mouse-face 'mode-line-highlight
+             'help-echo "Column number\n\
+mouse-1: Display Line and Column Mode Menu"))
+        (5 ,(propertize
+             " C%C"
+             'local-map mode-line-column-line-number-mode-map
+             'mouse-face 'mode-line-highlight
+             'help-echo "Column number\n\
+mouse-1: Display Line and Column Mode Menu")))))))
   "Mode line construct for displaying the position in the buffer.
 Normally displays the buffer percentage and, optionally, the
 buffer size, the line number and the column number.")
diff --git a/lisp/simple.el b/lisp/simple.el
index 5f70adedc4..0a8dbd1696 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7198,6 +7198,13 @@ column-number-mode
 If called from Lisp, enable the mode if ARG is omitted or nil."
   :global t :group 'mode-line)
 
+(defcustom column-number-indicator-zero-based t
+  "When set to true, Column Number mode displays columns starting
+from zero at the left margin of the window. Otherwise, displayed
+column numbers start from one."
+  :type 'boolean
+  :group 'mode-line)
+
 (define-minor-mode size-indication-mode
   "Toggle buffer size display in the mode line (Size Indication mode).
 With a prefix argument ARG, enable Size Indication mode if ARG is
diff --git a/src/buffer.c b/src/buffer.c
index 8ef27dee0f..261c0c15a3 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5608,8 +5608,11 @@ A string is printed verbatim in the mode line except for %-constructs:
 	For a modified read-only buffer, %* gives % and %+ gives *.
   %s -- print process status.   %l -- print the current line number.
   %c -- print the current column number (this makes editing slower).
+        Columns are numbered starting from the left margin, and the
+        leftmost column is displayed as zero.
         To make the column number update correctly in all cases,
 	`column-number-mode' must be non-nil.
+  %C -- Like %c, but the leftmost column is displayed as one.
   %i -- print the size of the buffer.
   %I -- like %i, but use k, M, G, etc., to abbreviate.
   %p -- print percent of buffer above top of window, or Top, Bot or All.
diff --git a/src/xdisp.c b/src/xdisp.c
index c6f8566523..cab01ec701 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -475,7 +475,7 @@ int windows_or_buffers_changed;
    used to track down the cause for this full-redisplay).
 
    Since the frame title uses the same %-constructs as the mode line
-   (except %c and %l), if this variable is non-zero, we also consider
+   (except %c, %C, and %l), if this variable is non-zero, we also consider
    redisplaying the title of each frame, see x_consider_frame_title.
 
    The `redisplay' bits are the same as those used for
@@ -11462,7 +11462,7 @@ window_buffer_changed (struct window *w)
   return (BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) != w->last_had_star;
 }
 
-/* True if W has %c in its mode line and mode line should be updated.  */
+/* True if W has %c or %C in its mode line and mode line should be updated.  */
 
 static bool
 mode_line_update_needed (struct window *w)
@@ -23520,7 +23520,8 @@ decode_mode_spec (struct window *w, register int c, int field_width,
       break;
 
     case 'c':
-      /* %c and %l are ignored in `frame-title-format'.
+    case 'C':
+      /* %c, %C, and %l are ignored in `frame-title-format'.
          (In redisplay_internal, the frame title is drawn _before_ the
          windows are updated, so the stuff which depends on actual
          window contents (such as %l) may fail to render properly, or
@@ -23530,8 +23531,9 @@ decode_mode_spec (struct window *w, register int c, int field_width,
       else
 	{
 	  ptrdiff_t col = current_column ();
+	  int disp_col = (c == 'C') ? col + 1 : col;
 	  w->column_number_displayed = col;
-	  pint2str (decode_mode_spec_buf, width, col);
+	  pint2str (decode_mode_spec_buf, width, disp_col);
 	  return decode_mode_spec_buf;
 	}
 
@@ -23579,7 +23581,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
 	ptrdiff_t topline, nlines, height;
 	ptrdiff_t junk;
 
-	/* %c and %l are ignored in `frame-title-format'.  */
+	/* %c, %C, and %l are ignored in `frame-title-format'.  */
 	if (mode_line_target == MODE_LINE_TITLE)
 	  return "";
 
@@ -31530,7 +31532,7 @@ This variable is not guaranteed to be accurate except while processing
 \(Assuming the window manager supports this feature.)
 
 This variable has the same structure as `mode-line-format', except that
-the %c and %l constructs are ignored.  It is used only on frames for
+the %c, %C, and %l constructs are ignored.  It is used only on frames for
 which no explicit name has been set (see `modify-frame-parameters').  */);
 
   DEFVAR_LISP ("icon-title-format", Vicon_title_format,

  parent reply	other threads:[~2017-04-17 15:21 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-16  1:28 Advice needed on modeline customization hack Perry E. Metzger
2017-04-16  1:55 ` Perry E. Metzger
2017-04-16  3:11 ` Stefan Monnier
2017-04-16 13:49   ` Perry E. Metzger
2017-04-16 14:07     ` Stefan Monnier
2017-04-16 14:46       ` Perry E. Metzger
2017-04-16 15:02         ` Clément Pit-Claudel
2017-04-16 16:09           ` Perry E. Metzger
2017-04-16 20:59             ` Clément Pit-Claudel
2017-04-16 22:06               ` Perry E. Metzger
2017-04-16 22:16                 ` Perry E. Metzger
2017-04-16 22:57                   ` Perry E. Metzger
2017-04-16 23:48                     ` Drew Adams
2017-04-17  0:13                       ` Perry E. Metzger
2017-04-17  6:00                     ` Eli Zaretskii
2017-04-17 12:53                       ` Perry E. Metzger
2017-04-17 14:17                         ` Eli Zaretskii
2017-04-17 15:24                           ` Perry E. Metzger
2017-04-17 15:34                             ` Eli Zaretskii
2017-04-17 18:07                               ` Perry E. Metzger
2017-04-17 18:23                                 ` Eli Zaretskii
2017-04-17 18:55                                   ` Perry E. Metzger
2017-04-17 19:07                                     ` Noam Postavsky
2017-04-17 19:18                                       ` Perry E. Metzger
2017-05-10 17:59                                   ` Eli Zaretskii
2017-04-17 15:21                         ` Perry E. Metzger [this message]
2017-04-17 15:31                           ` Eli Zaretskii
2017-04-17 15:55                             ` Perry E. Metzger
2017-04-17 16:13                               ` Eli Zaretskii
2017-04-17  6:02                 ` Eli Zaretskii
2017-04-17 12:32                   ` Perry E. Metzger

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=20170417112144.7de5cc4f@jabberwock.cb.piermont.com \
    --to=perry@piermont.com \
    --cc=cpitclaudel@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.