Skip to content

Instantly share code, notes, and snippets.

@fstamour
Created June 2, 2016 19:31
Show Gist options
  • Save fstamour/899746a0a0b7834885e96232b1f20d31 to your computer and use it in GitHub Desktop.
Save fstamour/899746a0a0b7834885e96232b1f20d31 to your computer and use it in GitHub Desktop.
Small emacs lisp function "If STRING starts with PREFIX, replace the PREFIX by NEW-PREFIX. Else, returns NIL."
(defun replace-prefix-if-present (string prefix new-prefix)
"If STRING starts with PREFIX, replace the PREFIX by NEW-PREFIX.
Else, returns NIL."
(if (string-prefix-p prefix string)
(concat new-prefix (substring string (length prefix)))
nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment