[elpa] master 5136626: * packages/csv-mode/csv-mode.el: Auto-shorten columns as well
branch: master commit 5136626383fd2fb7e96bbe694bbacee824a30dce Author: Stefan Monnier Commit: Stefan Monnier * packages/csv-mode/csv-mode.el: Auto-shorten columns as well (csv--column-widths): Also return the position of the widest field in each column. (csv-align-fields, csv--jit-align): Update accordingly. (csv--jit-width-change): New function. (csv--jit-merge-columns): Use it on overlays placed on the widest field of each column, to detect when they're shortened. --- packages/csv-mode/csv-mode.el | 68 ++- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/packages/csv-mode/csv-mode.el b/packages/csv-mode/csv-mode.el index 336f9d3..73d34bb 100644 --- a/packages/csv-mode/csv-mode.el +++ b/packages/csv-mode/csv-mode.el @@ -4,7 +4,7 @@ ;; Author: "Francis J. Wright" ;; Maintainer: emacs-de...@gnu.org -;; Version: 1.9 +;; Version: 1.10 ;; Package-Requires: ((emacs "24.1") (cl-lib "0.5")) ;; Keywords: convenience @@ -990,7 +990,9 @@ The fields yanked are those last killed by `csv-kill-fields'." (defun csv--column-widths (beg end) "Return a list of two lists (COLUMN-WIDTHS FIELD-WIDTHS). -COLUMN-WIDTHS contains the widths of the columns after point. +COLUMN-WIDTHS is a list of elements (WIDTH START END) +indicating the widths of the columns after point (and the position of the +widest field that determined the overall width). FIELD-WIDTHS contains the widths of each individual field after point." (let ((column-widths '()) @@ -1001,17 +1003,19 @@ point." (or (csv-not-looking-at-record) (let ((w column-widths) (col (current-column)) +(beg (point)) field-width) (while (not (eolp)) (csv-end-of-field) (setq field-width (- (current-column) col)) (push field-width field-widths) (if w - (if (> field-width (car w)) (setcar w field-width)) -(setq w (list field-width) + (if (> field-width (caar w)) + (setcar w (list field-width beg (point +(setq w (list (list field-width beg (point))) column-widths (nconc column-widths w))) (or (eolp) (forward-char)) ; Skip separator. - (setq w (cdr w) col (current-column) + (setq w (cdr w) col (current-column) beg (point) (forward-line)) (list column-widths (nreverse field-widths @@ -1057,7 +1061,7 @@ If there is no selected region, default to the whole buffer." (align-padding (if (bolp) 0 csv-align-padding)) (left-padding 0) (right-padding 0) (field-width (pop field-widths)) - (column-width (pop w)) + (column-width (car (pop w))) (x (- column-width field-width))) ; Required padding. (csv-end-of-field) (set-marker end (point)) ; End of current field. @@ -1372,23 +1376,59 @@ setting works better)." (defvar-local csv--jit-columns nil) (defun csv--jit-merge-columns (column-widths) - ;; FIXME: Keep track for each column of where is its widest field, - ;; and arrange to recompute that column's width when that line's - ;; field shrinks. + ;; FIXME: The incremental update (delayed by jit-lock-context-time) of column + ;; width is a bit jarring at times. It's OK while scrolling or when + ;; extending a column, but not right when enabling the csv-align-mode or + ;; when shortening the longest field (or deleting the line containing it), + ;; because in that case we have *several* cascaded updates, e.g.: + ;; - Remove the line with the longest field of column N. + ;; - Edit some line: this line is updated as if its field was the widest, + ;; hence its subsequent fields are too much to the left. + ;; - The rest is updated starting from the first few lines (according + ;; to jit-lock-chunk-size). + ;; - After the first few lines, come the next set of few lines, + ;; which may cause the previous few lines to need refresh again. + ;; - etc.. until arriving again at the edited line which is re-aligned + ;; again. + ;; - etc.. until the end of the windows, potentially causing yet more + ;; refreshes as we discover yet-wider fields for this column. (let ((old-columns csv--jit-columns) (changed nil)) (while (and old-columns column-widths) - (when (> (car column-widths) (car old-columns)) + (when (or (> (caar column-widths) (caar old-columns)) +;; Apparently modification-hooks aren't run when the +;; whole text containing the overlay is deleted (e.g. +;; the whole line), so detect this case here. +;; It's a bit too late, but better than never. +(null (overlay-buffer
[elpa] master 68e8ac3: * packages/csv-mode/csv-mode.el (csv-align--cursor-truncated): Fix C-e case
branch: master commit 68e8ac3632c9918b8266e10d67b30bafe4208a9d Author: Stefan Monnier Commit: Stefan Monnier * packages/csv-mode/csv-mode.el (csv-align--cursor-truncated): Fix C-e case --- packages/csv-mode/csv-mode.el | 15 +-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/csv-mode/csv-mode.el b/packages/csv-mode/csv-mode.el index 73d34bb..d8302b4 100644 --- a/packages/csv-mode/csv-mode.el +++ b/packages/csv-mode/csv-mode.el @@ -1464,9 +1464,20 @@ setting works better)." 'selective-display (if ellipsis (length ellipsis) 3))) -(defun csv-align--cursor-truncated (window _oldpos dir) +(defun csv-align--cursor-truncated (window oldpos dir) + ;; FIXME: Neither the `entered' nor the `left' event are guaranteed + ;; to be sent, and for the `left' case, even when we do get called, + ;; it may be unclear where the revealed text was (it's somewhere around + ;; `oldpos', but that position can be stale). + ;; Worse, if we have several windows displaying the buffer, when one + ;; cursor leaves we may need to keep the text revealed because of + ;; another window's cursor. (let* ((prop (if (eq dir 'entered) 'invisible 'csv--revealed)) - (pos (window-point window)) + (pos (cond + ((eq dir 'entered) (window-point window)) + (t (max (point-min) + (min (point-max) +(or oldpos (window-point window))) (start (cond ((and (> pos (point-min)) (eq (get-text-property (1- pos) prop) 'csv-truncate))
[elpa] master 2266172: * packages/loccur/loccur.el: Updated to version 1.2.4
branch: master commit 226617206cf7a4dc43be42a114524d97d829f32b Author: Alexey Veretennikov Commit: Alexey Veretennikov * packages/loccur/loccur.el: Updated to version 1.2.4 - The actions to perform then the loccur-mode was disactivated were incomplete. - Then loccur or loccur-no-highlight are called with universal prefix, i.e. with C-u before the command, the currently selected value is ignored. Then people want this behavior by default, it is better wrap the call to loccur with universal prefix, i.e. by implementing a helper function like this: (defun loccur-no-selection () (interactive) (let ((current-prefix-arg 1)) (call-interactively 'loccur))) And then just call this function instead of loccur. --- packages/loccur/loccur.el | 69 +++ 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/packages/loccur/loccur.el b/packages/loccur/loccur.el index e4293f4..b184eb2 100644 --- a/packages/loccur/loccur.el +++ b/packages/loccur/loccur.el @@ -5,11 +5,11 @@ ;; Author: Alexey Veretennikov ;; ;; Created: 2009-09-08 -;; Version: 1.2.3 -;; Package-Requires: ((cl-lib "0")) +;; Version: 1.2.4 +;; Package-Requires: ((emacs "24.3")) ;; Keywords: matching ;; URL: https://github.com/fourier/loccur -;; Compatibility: GNU Emacs 23.x, GNU Emacs 24.x +;; Compatibility: GNU Emacs 24.3 ;; ;; This file is part of GNU Emacs. ;; @@ -45,6 +45,24 @@ ;; ;;; Change Log: ;; +;; 2019-10-22 (1.2.4) +;;+ Added fix for the issue when the actions to perform +;; then the loccur-mode was disactivated were incomplete. +;;+ Then loccur or loccur-no-highlight are called with universal prefix, +;; i.e. with C-u before the command, the currently selected value is +;; ignored. +;; Then people want this behavior by default, it is better wrap the call +;; to loccur with universal prefix, i.e. by implementing a helper +;; function like this: +;; +;; (defun loccur-no-selection () +;;(interactive) +;; (let ((current-prefix-arg 1)) +;; (call-interactively +;; 'loccur))) +;; +;; And then just call this function instead of loccur. +;; ;; 2016-12-26 (1.2.3) ;;+ Removed empty line in the beginning of the buffer. ;;+ Added 'Tips and tricks' session to the README.md file @@ -96,6 +114,9 @@ a new window." :lighter " loccur" (if loccur-mode (loccur-1 loccur-current-search) +;; remove current search and turn off loccur mode +;; to allow to call `loccur' multiple times +(setf loccur-current-search nil) (loccur-remove-overlays) (recenter))) @@ -175,22 +196,20 @@ unhides lines again. When called interactively, either prompts the user for REGEXP or, when called with an active region, uses the content of the -region." +region, unless called with the universal prefix (C-u)" (interactive (cond ((region-active-p) (list (buffer-substring (mark) (point (loccur-mode (list nil)) (t - (list (read-string "Loccur: " (loccur-prompt) 'loccur-history) + (list (read-string "Loccur: " + (loccur-prompt) + 'loccur-history) (when (region-active-p) (deactivate-mark)) (if (or loccur-mode (= (length regex) 0)) - (progn -;; remove current search and turn off loccur mode -;; to allow to call `loccur' multiple times -(setf loccur-current-search nil) -(loccur-mode 0)) + (loccur-mode 0) ;; otherwise do as usual ;; if the regex argument is not equal to previous search (when (not (string-equal regex loccur-current-search)) @@ -205,20 +224,24 @@ region." "Return the default value of the prompt. Default value for prompt is a current word or active region(selection), -if its size is 1 line" - (let ((prompt - (if (and transient-mark-mode - mark-active) - (let ((pos1 (region-beginning)) - (pos2 (region-end))) - ;; Check if the start and the end of an active region is on - ;; the same line - (when (save-excursion - (goto-char pos1) - (<= pos2 (line-end-position))) +if its size is 1 line. +When the universal prefix is used, i.e. loccur called +with C-u prefix, returns empty string" + (if current-prefix-arg + "" +(let ((prompt + (if (and transient-mark-mode +mark-active) + (let ((pos1 (region-beginning)) + (pos2 (region-end))) + ;; Check if the start and the end of an active region is on + ;; the same line + (when (save-excursion +