0

How can I make a function that matches a target directory at point, changing the user name to another one?

Example, with cursor on /home/peter/web/ergomax.org I want to change from peter to paul, then store the result in a list that I can access later on.

2
  • In what sort of buffer? Dired? If not, how will the filenames be formatted, and how robust does the detection need to be? (filenames can contain all kinds of special characters, including spaces and even newlines potentially).
    – phils
    Aug 18, 2022 at 3:42
  • Yes, in dired would do. Files would not contain spaces or other weird things. The problematic task is how to add to a list that I can display. Another difficulty is where I will put the information. Might require another function to print or insert the list.
    – Dilna
    Aug 18, 2022 at 3:56

1 Answer 1

1

Try this:

(defvar my-list-for-later-access '())

(defun mash-homedir (username)
  "Substitute USERNAME into the pathname at point."
  (interactive "MUsername: ")
  (add-to-list
   'my-list-for-later-access
   (s-replace-regexp
    "/home/[^/]+/"
    (format "/home/%s/" username)
    (thing-at-point 'filename :no-properties))))
2
  • How can I view the list as I go along with the changes?
    – Dilna
    Aug 18, 2022 at 4:38
  • If I understand what you're asking correctly: just enter my-list-for-later-access RET in the minibuffer using M-x eval-expression RET (M-:) Aug 18, 2022 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.