Function: org-table-rotate-recalc-marks

org-table-rotate-recalc-marks is an autoloaded, interactive and byte-compiled function defined in org-table.el.gz.

Signature

(org-table-rotate-recalc-marks &optional NEWCHAR)

Documentation

Rotate the recalculation mark in the first column.

If in any row, the first field is not consistent with a mark, insert a new column for the markers. When there is an active region, change all the lines in the region, after prompting for the marking character. After each change, a message will be displayed indicating the meaning of the new mark.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
;;;###autoload
(defun org-table-rotate-recalc-marks (&optional newchar)
  "Rotate the recalculation mark in the first column.
If in any row, the first field is not consistent with a mark,
insert a new column for the markers.
When there is an active region, change all the lines in the region,
after prompting for the marking character.
After each change, a message will be displayed indicating the meaning
of the new mark."
  (interactive)
  (unless (org-at-table-p) (user-error "Not at a table"))
  (let* ((region (org-region-active-p))
	 (l1 (and region
		  (save-excursion (goto-char (region-beginning))
				  (copy-marker (line-beginning-position)))))
	 (l2 (and region
		  (save-excursion (goto-char (region-end))
				  (copy-marker (line-beginning-position)))))
	 (l (copy-marker (line-beginning-position)))
	 (col (org-table-current-column))
	 (newchar (if region
		      (char-to-string
		       (read-char-exclusive
			"Change region to what mark?  Type # * ! $ or SPC: "))
		    newchar))
	 (no-special-column
	  (save-excursion
	    (goto-char (org-table-begin))
	    (re-search-forward
	     "^[ \t]*|[^-|][^|]*[^#!$*_^| \t][^|]*|" (org-table-end) t))))
    (when (and newchar (not (assoc newchar org-recalc-marks)))
      (user-error "Invalid character `%s' in `org-table-rotate-recalc-marks'"
		  newchar))
    (when l1 (goto-char l1))
    (save-excursion
      (beginning-of-line)
      (unless (looking-at org-table-dataline-regexp)
	(user-error "Not at a table data line")))
    (when no-special-column
      (org-table-goto-column 1)
      (org-table-insert-column))
    (let ((previous-line-end (line-end-position))
	  (newchar
	   (save-excursion
	     (beginning-of-line)
	     (cond ((not (looking-at "^[ \t]*| *\\([#!$*^_ ]\\) *|")) "#")
		   (newchar)
		   (t (cadr (member (match-string 1)
				    (append (mapcar #'car org-recalc-marks)
					    '(" ")))))))))
      ;; Rotate mark in first row.
      (org-table-get-field 1 (format " %s " newchar))
      ;; Rotate marks in additional rows if a region is active.
      (when region
	(save-excursion
	  (forward-line)
	  (while (<= (point) l2)
	    (when (looking-at org-table-dataline-regexp)
	      (org-table-get-field 1 (format " %s " newchar)))
	    (forward-line))))
      ;; Only align if rotation actually changed lines' length.
      (when (/= previous-line-end (line-end-position)) (org-table-align)))
    (goto-char l)
    (org-table-goto-column (if no-special-column (1+ col) col))
    (when l1 (set-marker l1 nil))
    (when l2 (set-marker l2 nil))
    (set-marker l nil)
    (when (called-interactively-p 'interactive)
      (message "%s" (cdr (assoc newchar org-recalc-marks))))))