0

The function move-to-column does not seem to work in org-mode as expected when I move over links. When I move the cursor using the key shortcuts, the cursor moves over the displayed link as expected. But when I try to automate it and use the equivalent function the cursor moves over the literal representation of the link.

So I have the line of text with the link from character 32 to character 51, but when I go to the beginning of line and want to move to column 80 the cursor stops in the middle of the link.

Is there a version of move-to-column that understands org-mode links?

Example file fragment

* Question
How do I move cursor past [[https://emacs.stackexchange.com/questions/77500/in-org-mode-how-do-i-move-to-specified-column-when-i-move-over-links][my question]] so that it ends at column 65?

shows the discrepancy between visible column positions when I use descriptive links.

7
  • How are the links displayed? If they are displayed in the "descriptive" mode (where the link and the square bracked are invisible, both normal cursor motion and move-to-column behave as expected. When displayed literally, they also work as expected. What you cannot do is get a column number in one view and try to apply it in the other view. I guess I don't understand what you are doing.
    – NickD
    Jun 5, 2023 at 17:30
  • function what-cursor-position seems promising, but the documentation say it only prints what I want Jun 5, 2023 at 19:59
  • How does it show the discrepancy? When I do (with descriptive links) M-g TAB 65 I end up on the 5: is that what you want?
    – NickD
    Jun 5, 2023 at 20:22
  • In my example org fragment, we have a very long link with a short descriptive name, The discrepancy exists between the column position seen by lisp functions function and the displayed column position. Can you rewrite my answer with (beginning-of-line) (forward-char 80) ? Jun 5, 2023 at 20:31
  • 1
    Just some advice for next time: all you have to do is to describe exactly what you did, what you expected would happen and what really happened. Even if the question is incomplete at that point, any missing details can be clarified through questions in the comments. But don't say "I have this link from col 36 to col 51" - instead show the file (as you did in your edit). And when you say, "there is a discrepancy", show what the discrepancy is. It may be real, it may be a misunderstanding, but if there is a complete recipe, we can all try it out and see for ourselves.
    – NickD
    Jun 5, 2023 at 21:59

1 Answer 1

0

This is an updated version of the answer with suggestions from the comments.

(defun go-80 ()
  (interactive)
  (beginning-of-line)
  (move-to-column 80))
4
  • So does (beginning-of-line) (move-to-column 80) at least on upstream Emacs. If it does not work for you, please add the Emacs version in your question (which you should always do in any case).
    – NickD
    Jun 5, 2023 at 21:14
  • I just confirmed it. You are correct. So now I will wonder what I did wrong when I tried it the first time, sending myself and others down the wrong path. I apologise for the confusion. Jun 5, 2023 at 21:23
  • No problem - it's happened to everybody.
    – NickD
    Jun 5, 2023 at 21:24
  • 1
    This works because move-to-column (and current-column which was used in the original answer) specifically assigns a width of 0 to invisible characters. But it seems to me that the behavior of (forward-char 80) is buggy - but I'm still testing.
    – NickD
    Jun 6, 2023 at 0:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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