1

I have very long url, for example, https://www.youtube.com/channel/UCGM8KgUXqsS4d8-4rgWRWKg/playlists, how can I tailor it into a shorter form?

Like : https://www.youtube.com/channel/UC... [here ... means there are still content here] Remarks:

  1. There is a package called bitly, but I don't want to use;
  2. I do know this [[link][description]] stuff, I just want to display url.

Anyone has any ideas? Thanks!!!

1
  • It seems that this web just render my link the way I wish in org-mode.
    – Jiadong
    Jun 15, 2016 at 18:36

1 Answer 1

3

So this may not be exactly what you want but it turns the section that is underneath your point into a link that should be shorter.

(defun compress-org-link (arg)
  (interactive "P")
  (let ((url (thing-at-point 'url))
    (bounds (bounds-of-thing-at-point 'url)))
    (kill-region (car bounds) (cdr bounds))
    (insert (format "[[%s][%s]]" url (truncate-string-to-width url (if arg (prefix-numeric-value arg) 40) nil nil "...")))))

You can change the constant 40 to be a more suitable url length default. You can also feed the function a prefix arg to set the length of the final string.

3
  • I tried this function, it transform the original to [[][]] form, with the truncated link being the content of second []. this is good start. But the original link is automatically rendered my emacs. It seems the transformed link is NOT linked to the right place. Any this provide a new perspective. Thanks!
    – Jiadong
    Jun 15, 2016 at 19:19
  • Oh yes I see what I did wrong. It should be better now, I was grabbing the symbol instead of the url at the point. Let me know if this fixes your problem!
    – Jules
    Jun 15, 2016 at 19:33
  • Yeah, It worked! Thank you so much! It just make long url in org mode in a very brief form:)
    – Jiadong
    Jun 15, 2016 at 19:56

Your Answer

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

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