2

Often I find my self doing this

C-x C-f to create a file, while in the mini buffer prompt, paste a url like "https://github.com/seamusabshere/cache_method/issues/15" from the clipboard.

Since "https://github.com/seamusabshere/cache_method/issues/15" is not a "safe" file name, I end up manually fixing it to look like

https___github.com_seamusabshere_cache_method_issues_15

Can a pre-existing emacs function help me with this? I feel like converting a string to a filepath safe string is a common scenario in emacsland.

What I tried: Looked in M-x list for words like "normalize" "sanitize"

Another scenario: I'm in M-x shell, I have typed git checkout -b and have a jira ticket url in the clipboard. I want to create branch named after the jira ticket url.

2

Suppose you have copied the link or address you want to process.

After you have created a similar command:

(defun normalize-string-to-make-it-file/path-safe ()
  (interactive)
  (kill-new
   (mapconcat
    (function concat)
    (split-string
     (read-string "Input: ")
     "[:/]")
    "_")))

You can use "normalize-string-to-make-it-file/path-safe" to copy the converted result to the clipboard and paste it to use it.

In fact, I often use the corresponding conversion process, such as the name of the command, is also obtained in a similar way: replace the space in the title of your question with a minus sign.

  • didn't work for me, maybe I misunderstood you – american-ninja-warrior Oct 1 '18 at 3:31
  • Works for me. What exactly did you try? I did M-x normalize-string-to-make-it-file/path-safe then pasted https://github.com/seamusabshere/cache_method/issues/15 at the prompt. That put the resulting string in the kill-ring so I could yank it (with C-y): https___github.com_seamusabshere_cache_method_issues_15. Isn't that what you asked for? – Drew Nov 27 '18 at 22:23

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.