emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* little elisp help?
@ 2014-07-02 20:20 tom
  2014-07-02 20:31 ` Thorsten Jolitz
  2014-07-02 22:54 ` Eric Abrahamsen
  0 siblings, 2 replies; 6+ messages in thread
From: tom @ 2014-07-02 20:20 UTC (permalink / raw)
  To: emacs-orgmode

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

hi guys,

I have this:

(setq org-link-abbrev-alist
'(("foo" . "file:/path/to/%(myfun).txt")))

I'm trying to have "myfun" replace any spaces in the tag with underscores,
but I'm not having much luck. Would someone mind giving me a hint?

Thanks.

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

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

* Re: little elisp help?
  2014-07-02 20:20 little elisp help? tom
@ 2014-07-02 20:31 ` Thorsten Jolitz
  2014-07-02 22:09   ` tom
  2014-07-02 22:54 ` Eric Abrahamsen
  1 sibling, 1 reply; 6+ messages in thread
From: Thorsten Jolitz @ 2014-07-02 20:31 UTC (permalink / raw)
  To: emacs-orgmode

tom <scrawler@gmail.com> writes:

> hi guys,
>
> I have this:
>
> (setq org-link-abbrev-alist
> '(("foo" . "file:/path/to/%(myfun).txt")))
>
> I'm trying to have "myfun" replace any spaces in the tag with
> underscores, but I'm not having much luck. Would someone mind giving
> me a hint?

#+begin_src emacs-lisp
(let ((cons-pair '("foo bar  loo" "file:x")))
  (replace-regexp-in-string "[[:space:]]" "_" (car cons-pair)))
#+end_src

#+results:
: foo_bar__loo

-- 
cheers,
Thorsten

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

* Re: little elisp help?
  2014-07-02 20:31 ` Thorsten Jolitz
@ 2014-07-02 22:09   ` tom
  2014-07-03 12:44     ` Nick Dokos
  0 siblings, 1 reply; 6+ messages in thread
From: tom @ 2014-07-02 22:09 UTC (permalink / raw)
  To: emacs-orgmode

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

this

(setq org-link-abbrev-alist
'(("foo" . "file:/path/to/%s.txt")))

allow me to do this

[[foo:file to open]]

but it creates a file with spaces in the name.  so I'd like to replace "%s"
with "%(myfun)".

with your example, how can I get "foo bar  loo" from

[[foo:foo bar  loo]]

see what I mean?

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

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

* Re: little elisp help?
  2014-07-02 20:20 little elisp help? tom
  2014-07-02 20:31 ` Thorsten Jolitz
@ 2014-07-02 22:54 ` Eric Abrahamsen
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Abrahamsen @ 2014-07-02 22:54 UTC (permalink / raw)
  To: emacs-orgmode

tom <scrawler@gmail.com> writes:

> hi guys,
>
> I have this:
>
> (setq org-link-abbrev-alist
> '(("foo" . "file:/path/to/%(myfun).txt")))
>
> I'm trying to have "myfun" replace any spaces in the tag with
> underscores, but I'm not having much luck. Would someone mind giving
> me a hint?
>
> Thanks.

You might consider using the built-in `org-link-escape', it's likely to
do everything you need, and it's battle-tested!

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

* Re: little elisp help?
  2014-07-02 22:09   ` tom
@ 2014-07-03 12:44     ` Nick Dokos
  2014-07-03 18:36       ` tom
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Dokos @ 2014-07-03 12:44 UTC (permalink / raw)
  To: emacs-orgmode

tom <scrawler@gmail.com> writes:

> this
>
> (setq org-link-abbrev-alist
> '(("foo" . "file:/path/to/%s.txt")))
>
> allow me to do this
>
> [[foo:file to open]]
>
> but it creates a file with spaces in the name.  so I'd like to replace "%s" with "%(myfun)".
>
> with your example, how can I get "foo bar  loo" from
>
> [[foo:foo bar  loo]]
>
> see what I mean?
>

Using Thorsten's suggestion

--8<---------------cut here---------------start------------->8---
(setq org-link-abbrev-alist
'(("foo" . "file:/path/to/%(foobar).txt")))

(defun foobar (x)
  (replace-regexp-in-string "[[:space:]]" "_" x))
--8<---------------cut here---------------end--------------->8---

will turn

[[foo:foo bar  loo]]

to 

[[file:/path/to/foo_bar__loo.txt]]

when you click on it.
-- 
Nick

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

* Re: little elisp help?
  2014-07-03 12:44     ` Nick Dokos
@ 2014-07-03 18:36       ` tom
  0 siblings, 0 replies; 6+ messages in thread
From: tom @ 2014-07-03 18:36 UTC (permalink / raw)
  To: emacs-orgmode

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

Nick, that did the trick. Thanks very much everybody.


On Thu, Jul 3, 2014 at 7:44 AM, Nick Dokos <ndokos@gmail.com> wrote:

> tom <scrawler@gmail.com> writes:
>
> > this
> >
> > (setq org-link-abbrev-alist
> > '(("foo" . "file:/path/to/%s.txt")))
> >
> > allow me to do this
> >
> > [[foo:file to open]]
> >
> > but it creates a file with spaces in the name.  so I'd like to replace
> "%s" with "%(myfun)".
> >
> > with your example, how can I get "foo bar  loo" from
> >
> > [[foo:foo bar  loo]]
> >
> > see what I mean?
> >
>
> Using Thorsten's suggestion
>
> --8<---------------cut here---------------start------------->8---
> (setq org-link-abbrev-alist
> '(("foo" . "file:/path/to/%(foobar).txt")))
>
> (defun foobar (x)
>   (replace-regexp-in-string "[[:space:]]" "_" x))
> --8<---------------cut here---------------end--------------->8---
>
> will turn
>
> [[foo:foo bar  loo]]
>
> to
>
> [[file:/path/to/foo_bar__loo.txt]]
>
> when you click on it.
> --
> Nick
>
>
>

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

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

end of thread, other threads:[~2014-07-03 18:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-02 20:20 little elisp help? tom
2014-07-02 20:31 ` Thorsten Jolitz
2014-07-02 22:09   ` tom
2014-07-03 12:44     ` Nick Dokos
2014-07-03 18:36       ` tom
2014-07-02 22:54 ` Eric Abrahamsen

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).