1

What is a good, clean to deal with paths in emacs lisp? Common lisp has pathnames, Python has os.path. But I always seem to end up reinventing the wheel and resorting to manual regexes for simple path operations like getting a path basename, dirname, or joining paths together in a sane way.

2

The f.el package is a collection of prefixed functions wrapping existing functions as referenced in File Names and comes with a few of its own. I've found it useful to study its code for figuring out which built-in functions to use, but you can use it like a regular library as well.

  • thanks, this looks like it is exactly what I was looking for – erjoalgo Aug 22 '15 at 20:27
2

What you are, I think, calling "paths" Emacs and Emacs Lisp call "absolute" file or directory names. In Emacs language, a "path" is a list of absolute directory names, as used, for example, in the environment variable PATH and Emacs variables exec-path etc. (And yes, Common Lisp refers to these as "paths".)

Wrt the question of getting parts of a file name, combining them, etc., see the Elisp manual, node File Names and its subnodes, such as File Name Components.

Beyond that, your question is very general (and risks being closed as too broad). Please consider posing a specific question -- something that you want to do with file names or file-name components. Your question is OK as asking for general info about Emacs file-name functions, but a specific how-to question would also be useful.

  • 1
    I've used these before but I've found them lacking and not robust, eg I think the recommended way of joining components is just concatenating them together, and assuming directories always end in a slash, etc, which is too low level for my taste. I think my question is specific enough, for example, what is the emacs lisp analogue of Python's os.path library or CL's pathname which offer comprehensive tools for dealing with paths. – erjoalgo Aug 22 '15 at 20:31
  • This is obviously not the best way but I can't find your email anywhere, I've been using your help-fns+.el and there's a bug when a keymap is not bound to a symbol. Where can I report this (to you)? – erjoalgo Aug 23 '15 at 1:03
  • I understand that there is no variable documentation without a variable, all I'm saying is that you can easily omit it in the case that a keymap object is passed instead of a variable. my workaround it's as simple as (setq some-random-sym kmap) (describe-keymap 'some-random-sym), really using an advice and gensym. My case is that I'm creating anonymous, autogenerated keymaps (via (let ((kmap (make-sparse-keymap)) ...) from commands in a file and I'm binding one of its keys to a description of itself. Just thought I'd make a suggestion but no problem if you're not inclined towards it – erjoalgo Aug 23 '15 at 3:07
  • 1
    Yes, that's useful for non-interactive use -- good suggestion. I've done something similar now -- help-fns+.el – Drew Aug 23 '15 at 5:22
-2

elisp has the list load-path. When you want to add a new path to the scope, just do

(add-to-list 'load-path "my/new/path")

Then, supose you have a file.el in that directory. In the end of the file, put the line (provide 'file), and then you can require it with:

(require 'file)

You can also require files in subfolders of your load-path, if they are provided as such, with

(require 'subfolder/file)
  • thanks, but this doesn't answer my question. i'm trying to deal with paths in general, not just for the purpose of loading emacs lisp code. – erjoalgo Aug 22 '15 at 20:13

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.