emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Word under cursor to internal link
@ 2014-12-19  0:31 Chaitanya Krishna
  2014-12-19  1:08 ` John Kitchin
  0 siblings, 1 reply; 3+ messages in thread
From: Chaitanya Krishna @ 2014-12-19  0:31 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 231 bytes --]

Hello there,

Is there a shortcut to change word under cursor to an internal link?
Basically it is a pain trying to surround with two braces all the time!

C-c C-l does not prompt me to create an internal link.

Best regards,
Chai

[-- Attachment #2: Type: text/html, Size: 348 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Word under cursor to internal link
  2014-12-19  0:31 Chaitanya Krishna
@ 2014-12-19  1:08 ` John Kitchin
  0 siblings, 0 replies; 3+ messages in thread
From: John Kitchin @ 2014-12-19  1:08 UTC (permalink / raw)
  To: Chaitanya Krishna; +Cc: emacs-orgmode


Something like this seems to do approximately what you want:

#+BEGIN_SRC emacs-lisp
(defun word-to-link ()
  (interactive)
  (save-excursion
    (let (start end word)
      (backward-word)      
      (setq start (point))
      (forward-word)
      (setq end (point))
      (setq word (buffer-substring start end))
      (setf (buffer-substring start end)
	    (format "[[%s]]" word)))))
#+END_SRC

Chaitanya Krishna <icymist@gmail.com> writes:

> Hello there,
>
> Is there a shortcut to change word under cursor to an internal link?
> Basically it is a pain trying to surround with two braces all the
> time!
>
> C-c C-l does not prompt me to create an internal link.
>
> Best regards,
> Chai
>

-- 
-----------------------------------
John Kitchin
Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Word under cursor to internal link
@ 2014-12-19  1:45 Leu Zhe
  0 siblings, 0 replies; 3+ messages in thread
From: Leu Zhe @ 2014-12-19  1:45 UTC (permalink / raw)
  To: icymist, emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

You can use the function below to make it.
But in order to replace it rightly, you need to put you cursor inside the
word or at the beginning of the word.

(defun word-to-link ()
  (interactive)
  (let ((word (thing-at-point 'word)))
    (forward-word)
    (kill-word -1)
    (insert (format "[[%s]]" word))))

Hope it helps. And any improvement will be welcome.

[-- Attachment #2: Type: text/html, Size: 518 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-19  1:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-19  1:45 Word under cursor to internal link Leu Zhe
  -- strict thread matches above, loose matches on Subject: below --
2014-12-19  0:31 Chaitanya Krishna
2014-12-19  1:08 ` John Kitchin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).