bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#32106: 25.2: tabulated-list-resize-current-column [PATCH INCLUDED]


From: Drew Adams
Subject: bug#32106: 25.2: tabulated-list-resize-current-column [PATCH INCLUDED]
Date: Sun, 23 Jun 2019 19:56:23 -0700 (PDT)

> The code looks good to me -- Eli points out that it would be great if
> you could mode the column sized with a mouse, too, but I think that's
> kinda an orthogonal issue.  If somebody were to add a mouse-drag thing
> for tabulated mode (and somebody should), then it looks like your
> function would perhaps work well as the underlying function for that
> command.
> 
> So unless anybody objects, I'd like to include this command in
> tabulated-list.el (and add documentation, of course).

Yes, this is welcome.  There are a few (relatively minor)
problems with it, which are easily corrected.  The code
below is a bit better, I think.

. The doc string was wrong wrt `tabulated-list-format'
  being a "defcustom" (an option) - it's not.  And that
  var is always buffer-local (as are most things about
  `tabulated-list-mode').  So there's no reason for
  this command's doc to say its change is buffer-local.

. There's a mix of meanings of "column" in the code and
  comments, starting with the main doc-string line:

    "Change width of the current column by N columns."

  It's clearer to use "column" only for either an Emacs
  character/buffer column or a `tabulated-list-mode'
  table column.  In the code below I chose the latter,
  never calling the former a "column".

. It's handier for users for the numeric arg to always
  be provided by the numeric prefix arg (default: 1).
  No prompting, and the command can then be repeated by
  just holding down a key.

. With that change, by default the command widens the
  current column width, and its name can reflect that.
  Increasing by a negative number decreases, as usual.
  A separate command to narrow the column (decrease
  its width) should also be provided, for easy key
  binding.  A user can bind both widen and narrow
  commands to repeatable keys.

. No need to remember the start column.  REMEMBER-POS
  arg to `tabulated-list-print' takes care of that.

(defun tabulated-list-widen-current-column (&optional n)
  "Widen the current tabulated-list column by prefix-arg chars."
  (interactive "p")
  (let ((start        (current-column))
        (nb-cols      (length tabulated-list-format))
        (col-nb       0)
        (total-width  0)
        (found        nil)
        col-width)
    (while (and (not found)  (< col-nb nb-cols))
      (if (> start
             (setq total-width
                   (+ total-width
                      (setq col-width
                            (cadr (aref tabulated-list-format
                                        col-nb))))))
          (setq col-nb  (1+ col-nb))
        (setq found  t)
        (setf (cadr (aref tabulated-list-format col-nb))
              (max 1 (+ col-width n)))
        (tabulated-list-print t)
        (tabulated-list-init-header)))))

(defun tabulated-list-narrow-current-column (&optional n)
  "Narrow the current tabulated list column by N chars.
See `tabulated-list-increase-current-column'."
  (interactive "p")
  (tabulated-list-increase-current-column (- n)))





reply via email to

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