10

I have a column in an org-mode table that contains long file names. The interesting part of the filename is the last few characters rather than the first. For example, given the files below:

/data/capture/abcd_spectrum_01292000.dat
/data/capture/abcd_spectrum_02251435.dat
/data/capture/abcd_spectrum_02251847.dat
/data/capture/abcd_spectrum_02251848.dat
/data/capture/abcd_spectrum_02251848.dat
/data/capture/abcd_spectrum_02251849.dat
/data/capture/abcd_spectrum_02251851.dat
/data/capture/abcd_spectrum_02251852.dat
/data/capture/abcd_spectrum_02251852.dat
/data/capture/abcd_spectrum_02270910.dat

I want my org table to look like this:

|            File | TD | FD | MF | Notes:               |
|-----------------+----+----+----+----------------------|
|           <r15> |    |    |    | <l20>                |
| <=_01292000.dat |    |    |    |                      |
| <=_02251435.dat |    |    |    |                      |
| <=_02251847.dat |    |    |    |                      |
| <=_02251848.dat |    |    |    |                      |
| <=_02251848.dat |    |    |    |                      |
| <=_02251849.dat |    |    |    |                      |
| <=_02251851.dat |    |    |    |                      |
| <=_02251852.dat |    |    |    |                      |
| <=_02251852.dat |    |    |    |                      |
| <=_02270910.dat |    |    |    |                      |

But instead it looks like this:

|            File | TD | FD | MF | Notes:               |
|-----------------+----+----+----+----------------------|
|           <r15> |    |    |    | <l20>                |
| /data/capture=> |    |    |    |                      |
| /data/capture=> |    |    |    |                      |
| /data/capture=> |    |    |    |                      |
| /data/capture=> |    |    |    |                      |
| /data/capture=> |    |    |    |                      |
| /data/capture=> |    |    |    |                      |
| /data/capture=> |    |    |    |                      |
| /data/capture=> |    |    |    |                      |
| /data/capture=> |    |    |    |                      |
| /data/capture=> |    |    |    |                      |

Is it possible to make right-aligned columns truncate to the left, so that I can see the right-most part of the entries?

8

As far as I know, there is no built-in support for customizing truncation of table columns. However, you can modify the command org-table-align to achieve what you want:

  1. Find the file org-table.el. It is located in the directory of your org-mode installation. The fastest way to open it is via M-x find-library RET org-table RET.

  2. Copy the definition of org-table-align to your .emacs file.

  3. Replace

    (add-text-properties f1 (length xx) (list 'org-cwidth t) xx)
    (add-text-properties (- f1 2) f1
                   (list 'display org-narrow-column-arrow)
                   xx)))))
    

    with

    (let (s1 e1 s2 e2 arrow-string)
      (if (and falign1 (equal (downcase falign1) "r"))
          (setq s1 0
                e1 (- (length xx) f1)
                s2 (- (length xx) f1)
                e2 (- (length xx) (- f1 2))
                arrow-string "<=")
        (setq s1 f1
              e1 (length xx)
              s2 (- f1 2)
              e2 f1
              arrow-string org-narrow-column-arrow))
      (add-text-properties s1 e1 (list 'org-cwidth t) xx)
      (add-text-properties s2 e2 (list 'display arrow-string) xx))))))
    

Tested using version 8.2.8 of org-mode.

  • 3
    Can this be done as advice? In general I try to avoid directly modifying existing libraries if possible. Especially ones that get frequent updates from up-stream sources. EDIT: I see now that you are recommending creating a copy of the function in my init file. I guess that is better than directly modifying it. – nispio Oct 6 '14 at 22:35
  • @nispio "In general I try to avoid directly modifying existing libraries if possible." That is exactly why I suggested creating a copy of the function :) Right now I don't see how you would do this using advice, since the arguments that are relevant for determining which portion of a cell to hide are calculated on the fly when calling add-text-properties in the original command. – itsjeyd Oct 6 '14 at 22:50
  • It would be nice if a future version of org-mode would break this part out into a separate defun so that it could more easily be advised or replaced. Are the org-mode developers pretty open to pull requests for things like this? – nispio Oct 6 '14 at 23:07
  • @nispio Not sure about pull requests, but you could try submitting a suggestion along these lines to the mailing list. EDIT: It says here that you can also submit patches to the mailing list, and this page describes the "preferred way of submitting patches" to org-mode. – itsjeyd Oct 6 '14 at 23:12

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.