List for cgit developers and users
 help / color / mirror / Atom feed
From: Jason at zx2c4.com (Jason A. Donenfeld)
Subject: [PATCH 2/2] bugfix: make ss-diff correctly handle tab expansion
Date: Tue, 30 Oct 2012 10:56:33 -0600	[thread overview]
Message-ID: <CAHmME9pi8jJtKy+8nZ83+0DqLkZM1Ei-pJS=p7V3NG-P8X310A@mail.gmail.com> (raw)
In-Reply-To: <20121030145653.GB378591@plenz.com>

I haven't reviewed this carefully yet, but off hand, it seems like a
tab is always between 1 and 8 spaces long.

Let the first column be column 1, and any column be column C. Then,

if C % 8 == 1, spaces := 8
if C % 8 == 2, spaces := 7
if C % 8 == 3, spaces := 6
if C % 8 == 4, spaces := 5
if C % 8 == 5, spaces := 4
if C % 8 == 6, spaces := 3
if C % 8 == 7, spaces := 2
if C % 8 == 0, spaces := 1

This is the intuitive approach visually confirmed by mucking around
inside of VIM. Now let's play with it for 0 indexed columns. We can
just rotate:

if C % 8 == 0, spaces := 8
if C % 8 == 1, spaces := 7
if C % 8 == 2, spaces := 6
if C % 8 == 3, spaces := 5
if C % 8 == 4, spaces := 4
if C % 8 == 5, spaces := 3
if C % 8 == 6, spaces := 2
if C % 8 == 7, spaces := 1


The formula is then just:

8 - ( C % 8 )

Which should be a pretty simple way of calculating it, since "the
0-based column we're at" is just the current length.

Doing it this way, you don't have to hard code the initial space,
since m % n < n.




  reply	other threads:[~2012-10-30 16:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-30 12:56 [PATCH 0/2] side-by-side-diff fixes plenz
2012-10-30 12:56 ` [PATCH 1/2] bugfix: in ssdiff, fix line number links plenz
2012-10-30 16:37   ` Jason
2012-10-30 12:56 ` [PATCH 2/2] bugfix: make ss-diff correctly handle tab expansion plenz
2012-10-30 14:56   ` plenz
2012-10-30 16:56     ` Jason [this message]
2012-10-30 17:12       ` plenz
2012-10-30 17:25         ` Jason
2012-10-30 17:52           ` plenz
2012-11-15  0:03             ` Jason
2012-11-15 16:35               ` [PATCH v2] " plenz
2013-02-01 12:51                 ` Jason

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='CAHmME9pi8jJtKy+8nZ83+0DqLkZM1Ei-pJS=p7V3NG-P8X310A@mail.gmail.com' \
    --to=cgit@lists.zx2c4.com \
    /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.
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 NNTP newsgroup(s).