Fix bugs wrt invisibility handline.

* org-compat.el (org-move-to-column): Always ignore invisible
text in agenda buffer, and when there is both a bracket link
and '(org-link) as a member of `buffer-invisibility-spec'.
Add a docstring.

* org.el (org-align-tags-here): Add docstring and remove
useless arguments when calling `org-move-to-column'.

* org-table.el (org-table-copy-down)
(org-table-find-dataline, org-table-move-row)
(org-table-insert-hline, org-table-kill-row):
* org-agenda.el (org-agenda-next-item)
(org-agenda-previous-item, org-agenda-todo)
(org-agenda-priority, org-agenda-show-new-time)
(org-agenda-clock-in, org-agenda-clock-out): Remove useless
arguments when calling `org-move-to-column'.

This fixes the issue about S-RET not placing the cursor in the right
table field when M-x org-toggle-link-display RET removed '(org-link)
from `buffer-invisibility-spec' and some other discrepancies (like
S-M-<up> not restoring point correctly when there is a bracket link
before point, or M-x org-clock-display RET not aligning overlays
correctly, etc.

Thanks to Matt Lundin and Michael Brand for tracking issues
about this.
This commit is contained in:
Bastien Guerry 2014-03-20 15:04:49 +01:00
parent 8bab38bcba
commit a3ec854cab
4 changed files with 36 additions and 22 deletions

View File

@ -8275,7 +8275,7 @@ When called with a prefix argument, include all archive files as well."
(when (next-single-property-change (point-at-eol) 'org-marker)
(move-end-of-line 1)
(goto-char (next-single-property-change (point) 'org-marker))))
(org-move-to-column col nil nil t))
(org-move-to-column col))
(org-agenda-do-context-action))
(defun org-agenda-previous-item (n)
@ -8287,7 +8287,7 @@ When called with a prefix argument, include all archive files as well."
(move-end-of-line 0)
(previous-single-property-change (point) 'org-marker))))
(if goto (goto-char goto))
(org-move-to-column col nil nil t)))
(org-move-to-column col)))
(org-agenda-do-context-action))
(defun org-agenda-do-context-action ()
@ -8798,7 +8798,7 @@ the same tree node, and the headline of the tree node in the Org-mode file."
(string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
newhead)
(org-agenda-unmark-clocking-task))
(org-move-to-column col nil nil t))))
(org-move-to-column col))))
(defun org-agenda-add-note (&optional arg)
"Add a time-stamped note to the entry at point."
@ -8954,7 +8954,7 @@ Called with a universal prefix arg, show the priority instead of setting it."
(end-of-line 1)
(setq newhead (org-get-heading)))
(org-agenda-change-all-lines newhead hdmarker)
(org-move-to-column col nil nil t)))))
(org-move-to-column col)))))
;; FIXME: should fix the tags property of the agenda line.
(defun org-agenda-set-tags (&optional tag onoff)
@ -9163,7 +9163,7 @@ Called with a universal prefix arg, show the priority instead of setting it."
(goto-char (point-max))
(while (not (bobp))
(when (equal marker (org-get-at-bol 'org-marker))
(org-move-to-column (- (window-width) (length stamp)) t nil t)
(org-move-to-column (- (window-width) (length stamp)) t)
(org-agenda-fix-tags-filter-overlays-at (point))
(if (featurep 'xemacs)
;; Use `duplicable' property to trigger undo recording
@ -9265,7 +9265,7 @@ ARG is passed through to `org-deadline'."
(org-clock-in arg)
(setq newhead (org-get-heading)))
(org-agenda-change-all-lines newhead hdmarker))
(org-move-to-column col nil nil t))))
(org-move-to-column col))))
(defun org-agenda-clock-out ()
"Stop the currently running clock."
@ -9285,7 +9285,7 @@ ARG is passed through to `org-deadline'."
(setq newhead (org-get-heading))))))
(org-agenda-change-all-lines newhead marker)
(move-marker marker nil)
(org-move-to-column col nil nil t)
(org-move-to-column col)
(org-agenda-unmark-clocking-task)))
(defun org-agenda-clock-cancel (&optional arg)

View File

@ -343,10 +343,25 @@ Works on both Emacs and XEmacs."
(org-xemacs-without-invisibility (indent-line-to column))
(indent-line-to column)))
(defun org-move-to-column (column &optional force buffer ignore-invisible)
(let ((buffer-invisibility-spec ignore-invisible))
(defun org-move-to-column (column &optional force buffer)
"Move to column COLUMN.
Pass COLUMN and FORCE to `move-to-column'.
Pass BUFFER to the XEmacs version of `move-to-column'."
(let ((buffer-invisibility-spec
(if (or
;; Ignore all visibility spec in agenda
(not (derived-mode-p 'org-mode))
;; Ignore bracket links elsewere
(and (save-excursion
(forward-line 0)
(looking-at (concat "^.*" org-bracket-link-regexp)))
(member '(org-link)
buffer-invisibility-spec)))
t
buffer-invisibility-spec)))
(if (featurep 'xemacs)
(org-xemacs-without-invisibility (move-to-column column force buffer))
(org-xemacs-without-invisibility
(move-to-column column force buffer))
(move-to-column column force))))
(defun org-get-x-clipboard-compat (value)

View File

@ -1136,12 +1136,12 @@ copying. In the case of a timestamp, increment by one day."
(< (string-to-number txt) 100000000))
(setq txt (format "%d" (+ (string-to-number txt) 1))))
(insert txt)
(org-move-to-column col nil nil t)
(org-move-to-column col)
(if (and org-table-copy-increment (org-at-timestamp-p t))
(org-timestamp-up-day)
(org-table-maybe-recalculate-line))
(org-table-align)
(org-move-to-column col nil nil t))
(org-move-to-column col))
(user-error "No non-empty field found"))))
(defun org-table-check-inside-data-field (&optional noerror)
@ -1370,12 +1370,12 @@ However, when FORCE is non-nil, create new columns if necessary."
t
(let ((col (current-column))
(end (org-table-end)))
(org-move-to-column col nil nil t)
(org-move-to-column col)
(while (and (< (point) end)
(or (not (= (current-column) col))
(org-at-table-hline-p)))
(beginning-of-line 2)
(org-move-to-column col nil nil t))
(org-move-to-column col))
(if (and (org-at-table-p)
(not (org-at-table-hline-p)))
t
@ -1524,7 +1524,7 @@ first dline below it is used. When ABOVE is non-nil, the one above is used."
(beginning-of-line tonew)
(insert txt)
(beginning-of-line 0)
(org-move-to-column col nil nil t)
(org-move-to-column col)
(unless (or hline1p hline2p
(not (or (not org-table-fix-formulas-confirm)
(funcall org-table-fix-formulas-confirm
@ -1576,7 +1576,7 @@ With prefix ABOVE, insert above the current line."
(beginning-of-line (if above 1 2))
(insert line "\n")
(beginning-of-line (if above 1 -1))
(org-move-to-column col nil nil t)
(org-move-to-column col)
(and org-table-overlay-coordinates (org-table-align))))
;;;###autoload
@ -1616,7 +1616,7 @@ In particular, this does handle wide and invisible characters."
(dline (org-table-current-dline)))
(kill-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
(if (not (org-at-table-p)) (beginning-of-line 0))
(org-move-to-column col nil nil t)
(org-move-to-column col)
(when (or (not org-table-fix-formulas-confirm)
(funcall org-table-fix-formulas-confirm "Fix formulas? "))
(org-table-fix-formulas "@" (list (cons (number-to-string dline) "INVALID"))

View File

@ -14403,6 +14403,7 @@ If ONOFF is `on' or `off', don't toggle but set to this state."
(defun org-align-tags-here (to-col)
;; Assumes that this is a headline
"Align tags on the current headline to TO-COL."
(let ((pos (point)) (col (current-column)) ncol tags-l p)
(beginning-of-line 1)
(if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
@ -14421,7 +14422,7 @@ If ONOFF is `on' or `off', don't toggle but set to this state."
(insert (make-string (- ncol (current-column)) ?\ ))
(setq ncol (current-column))
(when indent-tabs-mode (tabify p (point-at-eol)))
(org-move-to-column (min ncol col) t nil t))
(org-move-to-column (min ncol col)))
(goto-char pos))))
(defun org-set-tags-command (&optional arg just-align)
@ -14480,9 +14481,7 @@ If DATA is nil or the empty string, any tags will be removed."
(defun org-set-tags (&optional arg just-align)
"Set the tags for the current headline.
With prefix ARG, realign all tags in headings in the current buffer.
When JUST-ALIGN is non-nil, only align tags.
When JUST-ALIGN is 'ignore-column, align tags without trying to set
the column by ignoring invisible text."
When JUST-ALIGN is non-nil, only align tags."
(interactive "P")
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
(let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
@ -14579,7 +14578,7 @@ the column by ignoring invisible text."
(and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
tags)
(t (error "Tags alignment failed")))
(org-move-to-column col nil nil (not (eq just-align 'ignore-column)))
(org-move-to-column col)
(unless just-align
(run-hooks 'org-after-tags-change-hook))))))