In Elisp, how to get path string with slash properly inserted?

后端 未结 6 870
闹比i
闹比i 2021-01-02 05:46

I am manually constructing path strings in Elisp by concatenating partial paths and directory names. Unfortunately sometimes the paths end with slash, sometimes not. Theref

6条回答
  •  情话喂你
    2021-01-02 06:30

    Something like this should work as a starting point, although you'd want to flesh it out a bit to make it platform independent, etc.

    (defun append-path-component (path new-part)
      (if (string-match ".*/$" path)
        (concat path new-part)
        (concat path "/" new-part)))
    

    As per usual, there's probably some bit of elisp that already does this that I'm just not aware of.

提交回复
热议问题