git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-blame.el: pick a set of random colors for each git-blame turn

From
David Kågedal <davidk@lysator.liu.se>
Date
Mar 28, 2007, 12:02 UTC
Message-ID
<871wj94lua.fsf@morpheus.local>
In-Reply-To
<200703281031.l2SAVhj7004802@localhost.localdomain>
Xavier Maillard <zedek@gnu.org> writes:
Show 6 quoted lines
> I thought it would be cool to have different set of colors for each
> git-blame-mode. Function `git-blame-new-commit' does this for us
> picking when possible, a random colors based on the set we build on
> startup. When it fails, `git-blame-ancient-color' will be used. We
> also take care not to use the same color more than once (thank you
> David Kågedal).
Closer, but still no cigar :-)
Show 22 quoted lines
>  (defun git-blame-new-commit (hash src-line res-line num-lines)
>    (save-excursion
>      (set-buffer git-blame-file)
>      (let ((info (gethash hash git-blame-cache))
>            (inhibit-point-motion-hooks t)
> -          (inhibit-modification-hooks t))
> +          (inhibit-modification-hooks t)
> +	  (colors git-blame-colors))
>        (when (not info)
> -        (let ((color (pop git-blame-colors)))
> -          (unless color
> -            (setq color git-blame-ancient-color))
> -          (setq info (list hash src-line res-line num-lines
> +	;; Assign a random color to each new commit info
> +	;; Take care not to select the same color multiple times
> +	(let ((color (if colors
> +			 (git-blame-random-pop colors)
> +		       git-blame-ancient-color)))
> +	  (setq info (list hash src-line res-line num-lines
>                             (git-describe-commit hash)
>                             (cons 'color color))))
>          (puthash hash info git-blame-cache))

You are still making a copy of the list head pointer (colors -> git-blame-colors), and then you do (git-blame-random-pop colors). This will not update git-blame-colors if the first element was popped, which means that you will keep reusing that color. Since you really do want to always update the buffer-local git-blame-colors, I don't see why you bind a local variable and work with that instead.

And the last diff line is whitespace-only. You replaced eight spaces with a TAB.

-- 
David Kågedal
Previous: Xavier MaillardNext: Xavier Maillard
Message 9 of 12 in “git-blame.el: pick a set of random colors when blaming”
  1. 2/2 git-blame.el: pick a set of random colors when blamingXavier Maillard, Mar 26, 2007
  2. David KågedalMar 27, 2007
  3. Xavier MaillardMar 27, 2007
  4. David KågedalMar 28, 2007
  5. git-blame.el: pick a set of random colors for each git-blame turnXavier Maillard, Mar 27, 2007
  6. David KågedalMar 28, 2007
  7. Xavier MaillardMar 28, 2007
  8. git-blame.el: pick a set of random colors for each git-blame turnXavier Maillard, Mar 28, 2007
  9. David KågedalMar 28, 2007
  10. Xavier MaillardMar 28, 2007
  11. David KågedalMar 29, 2007
  12. Xavier MaillardMar 29, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.