11

Sometimes it is convenient to set a manual column width when creating a table in org-mode. This makes it so that columns do not have to grow to the size of their longest entry. When an entry in and org-mode table is longer than the column it is found in, the entry gets visually truncated with a => symbol at the end.

I know that I can do C-c ` to use org-table-edit-field, but this requires pressing C-c C-c to close the preview window and get back to the org-mode buffer. Calling the same command with a prefix argument C-u C-c ` makes the full field visible so that it can be edited in place, but it is still tedious if I want to quickly preview 5-10 fields in quick succession.

LibreOffice Calc has a preview field at the top of a spreadsheet (so does MS Excel) which shows the value of the currently selected field:

preview field in LibreOffice Calc

Is it possible to get a similar preview when editing an org-mode table? The minibuffer seems like one good place for it, although it might have the side effect of filling up the *Messages* buffer quickly. A dedicated mini window at the top or bottom of the buffer would also work.

  • 3
    As explained here, you can preview contents of truncated fields by hovering over them with the mouse (no clicks necessary). If you have tooltip-mode turned on, the contents will be shown in a tooltip; otherwise they will be displayed in the echo area. – itsjeyd Oct 7 '14 at 18:34
  • If I liked using the mouse, I would make my tables in Excel... ;-) – nispio Oct 7 '14 at 18:37
  • Just wanted to make sure you are aware of this option... – itsjeyd Oct 7 '14 at 18:38
11

Inspired by Juancho's answer, I decided to use the header line to display the value of the current field. While I was at it, I decided it would be nice to show the location of the field in the header as well:

Org table header in action

This is the code I used to achieve it:

(defun my-trim-string (arg) 
  "Simple function for trimming the whitespace from the ends of
 a string. Also removes any string properties such as font faces."
  (let ((str (substring-no-properties arg)))
    (when (string-match "^[ \t]+" str)
      (setq str (replace-match "" nil nil str)))
    (when (string-match "[ \t]+$" str)
      (setq str (replace-match "" nil nil str)))
    str))

(defun my-org-table-location (&optional arg)
  "Get the location of the current field in the table"
  (interactive "P")
  (when (eq 'org-mode major-mode)
    (org-table-get-specials)
    (let* ((row (org-table-current-dline))
           (col (org-table-current-column))
           (loc (if arg
                    (format "%c%02d" (+ 64 col) row)
                  (format "@%d$%d" row col))))
      (when (called-interactively-p 'any)
        (message "Field Location: %s" loc))
      loc)))

(defun my-org-table-field (&optional arg)
  "Get the value of the current field in the table"
  (interactive "P")
  (when (eq 'org-mode major-mode)
    (org-table-get-specials)
    (let* ((formula (org-table-current-field-formula))
           (value (my-trim-string (org-table-get-field)))
           (field (or (and arg formula) value)))
      (when (called-interactively-p 'any)
        (message "Field Value: %s" loc))
      field)))

;; Define the format for the header line in Org mode
(setq my-org-table-header
      (list '(:eval (let ((loc (my-org-table-location))
                          (field (my-org-table-field)))
                      (format " %s: %s" loc field)))))

(defun my-org-mode-setup ()
  "Apply custom setup to org-mode buffers"
  (setq-local header-line-format my-org-table-header))
(add-hook 'org-mode-hook 'my-org-mode-setup)

It has withstood a few days of (minimal) testing, so I decided to go ahead and share it. If anybody else ends up using this, please let me know if you encounter any problems with it.

9

Inspired by seth's answer, you may always display the tooltip text on the header line (which is a little-known mode line at the top of the window).

Execute the following:

(setq-default header-line-format (list '(:eval (help-at-pt-kbd-string))))

Now, every time the text under the point has a tooltip property, it will be displayed on the header line.

Actually, org-table tooltips contain an annoying prefix with instructions, but it is an approximation to your problem.

  • Thank you! I expanded on this idea to come up with a solution that shows the value of any field (not just the ones with tooltips). – nispio Oct 10 '14 at 17:07
8

If you put your cursor in the cell and hit C-h . it'll show the help text for that cell in the echo area. The help text contains the full value as well as the other help text. Kind of noisy but it shows the value.

See display-local-help and Help Echo.

3

This is an old question, but let me add this.

(add-hook 'org-mode-hook
          '(lambda ()
             (setq-local header-line-format (list '(:eval (substring-no-properties (org-table-get-field)))))
           ))

This is a more direct way to implement @nispio 's solution, I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.