File: project.el.html

This file contains generic infrastructure for dealing with projects, some utility functions, and commands using that infrastructure.

The goal is to make it easier for Lisp programs to operate on the current project, without having to know which package handles detection of that project type, parsing its config files, etc.

This file consists of following parts:

Infrastructure (the public API):

Function project-current that returns the current project instance based on the value of the hook project-find-functions, and several generic functions that act on it.

project-root must be defined for every project. project-files can be overridden for performance purposes. project-ignores and project-external-roots describe the project files and its relations to external directories. project-files should be consistent with project-ignores.

project-buffers can be overridden if the project has some unusual shape (e.g. it contains files residing outside of its root, or some files inside the root must not be considered a part of it). It should be consistent with project-files.

This list can change in future versions.

Transient project:

An instance of this type can be returned by project-current if no project was detected automatically, and the user had to pick a directory manually. The fileset it describes is the whole directory, with the exception of some standard ignored files and directories. This type has little purpose otherwise, as the only generic function it provides an override for is project-root.

VC-aware project:

Originally conceived as an example implementation, now it's a relatively fast backend that delegates to 'git ls-files' or 'hg status' to list the project's files. It honors the VC ignore files, but supports additions to the list using the user option project-vc-ignores (usually through .dir-locals.el). See the customization group project-vc for other options that control its behavior.

The file listing uses the VC backend function project-list-files. If the current VC backend does not implement it, the default mechanism based on find-program is used as fallback.

  project-list-files (dir extra-ignores)

DIR is a directory inside the repository. EXTRA-IGNORES is a list of globs in the format of project-ignores.

This project type can also be used for non-VCS controlled directories, see the variable project-vc-extra-root-markers.

Utils:

project-combine-directories and project-subtract-directories, mainly for use in the abovementioned generics' implementations.

project-known-project-roots and project-remember-project to interact with the "known projects" list.

Commands:

project-prefix-map contains the full list of commands defined in this package. This map uses the prefix C-x p by default. Type C-x p f to find file in the current project. Type C-x p C-h to see all available commands and bindings.

All commands defined in this package are implemented using the public API only. As a result, they will work with any project backend that follows the protocol.

Any third-party code that wants to use this package should likewise target the public API. Use any of the built-in commands as the example.

How to create a new backend:

- Consider whether you really should, or whether there are other
ways to reach your goals. If the backend's performance is significantly lower than that of the built-in one, and it's first in the list, it will affect all commands that use it. Unless you are going to be using it only yourself or in special circumstances, you will probably want it to be fast, and it's unlikely to be a trivial endeavor. project-files is the method to optimize (the default implementation gets slower the more files the directory has, and the longer the list of ignores is).

- Choose the format of the value that represents a project for your
backend (we call it project instance). Don't use any of the formats from other backends. The format can be arbitrary, as long as the datatype is something cl-defmethod can dispatch on. The value should be stable (when compared with equal) across invocations, meaning calls to that function from buffers belonging to the same project should return equal values.

- Write a new function that will determine the current project
based on the directory and add it to project-find-functions
(which see) using add-hook. It is a good idea to depend on the
directory only, and not on the current major mode, for example. Because the usual expectation is that all files in the directory belong to the same project (even if some/most of them are ignored).

- Define new methods for some or all generic functions for this
backend using cl-defmethod. A project-root method is mandatory, project-files is recommended, the rest are optional.

Defined variables (32)

project--listList structure containing root directories of known projects.
project-buffers-viewerFunction to use in ‘project-list-buffers’ to render the list.
project-compilation-buffer-name-functionFunction to compute the name of a project compilation buffer.
project-current-directory-overrideValue to use instead of ‘default-directory’ when detecting the project.
project-current-inhibit-promptValue to use instead of ‘default-directory’ when detecting the project.
project-file-history-behaviorIf ‘relativize’, entries in ‘file-name-history’ are adjusted.
project-files-relative-namesIf non-nil, ‘project-files’ is allowed to return relative file names.
project-find-functionsSpecial hook to find the project containing a given directory.
project-find-matching-buffer-functionFunction to switch to a matching buffer in another project.
project-ignore-buffer-conditionsList of conditions to filter the buffers to be switched to.
project-key-prompt-styleWhich presentation to use when asking to choose a command by key.
project-kill-buffer-conditionsList of conditions to kill buffers related to a project.
project-kill-buffers-display-buffer-listNon-nil to display list of buffers to kill before killing project buffers.
project-list-excludeExclude projects from being remembered by ‘project-remember-project’.
project-list-fileFile in which to save the list of known projects.
project-mode-lineWhether to show current project name and Project menu on the mode line.
project-mode-line-faceFace name to use for the project name on the mode line.
project-other-frame-mapKeymap for project commands that display buffers in other frames.
project-other-window-mapKeymap for project commands that display buffers in other windows.
project-prefix-mapKeymap for project commands.
project-prompterFunction to call to prompt for a project.
project-prune-zombie-projectsRemove automatically from project list the projects that were removed.
project-read-file-name-functionFunction to call to read a file name from a list.
project-switch-commandsAlist mapping commands to descriptions.
project-switch-use-entire-mapWhether ‘project-switch-project’ will use the entire ‘project-prefix-map’.
project-vc-backend-markers-alistAssociative list assigning root markers to VC backend symbols.
project-vc-external-roots-functionFunction that returns a list of external roots.
project-vc-extra-root-markersList of additional markers to signal project roots.
project-vc-ignoresList of patterns to add to ‘project-ignores’.
project-vc-include-untrackedWhen non-nil, the VC-aware project backend includes untracked files.
project-vc-merge-submodulesNon-nil to consider submodules part of the parent project.
project-vc-nameWhen non-nil, the name of the current VC-aware project.

Defined functions (94)

project--buffer-check(BUF CONDITIONS)
project--buffers-completion-table(BUFFERS)
project--buffers-to-kill(PR)
project--completing-read-strict(PROMPT COLLECTION &optional PREDICATE HIST MB-DEFAULT COMMON-PARENT-DIRECTORY)
project--completion-table-with-category(TABLE CATEGORY)
project--delete-zombie-projects(PREDICATE)
project--dir-ignores(PROJECT DIR)
project--ensure-read-project-list()
project--file-completion-table(ALL-FILES)
project--files-in-directory(DIR IGNORES &optional FILES)
project--find-default-from(FILENAME PROJECT)
project--find-in-directory(DIR)
project--find-regexp-in-files(REGEXP FILES)
project--keymap-prompt()
project--menu-prompt()
project--other-place-command(ACTION &optional MAP)
project--other-place-prefix(PLACE &optional EXTRA-KEYMAP)
project--read-file-absolute(PROMPT ALL-FILES &optional PREDICATE HIST MB-DEFAULT)
project--read-file-cpd-relative(PROMPT ALL-FILES &optional PREDICATE HIST MB-DEFAULT)
project--read-file-name(PROJECT PROMPT ALL-FILES &optional PREDICATE HIST MB-DEFAULT)
project--read-project-list()
project--remember-dir(ROOT &optional NO-WRITE STABLE)
project--remote-file-names(LOCAL-FILES)
project--remove-from-project-list(PROJECT-ROOT REPORT-MESSAGE)
project--submodule-p(ROOT)
project--switch-project-command(&optional DIR)
project--transplant-file-name(FILENAME PROJECT)
project--value-in-dir(VAR DIR)
project--vc-list-files(DIR BACKEND EXTRA-IGNORES)
project--vc-merge-submodules-p(DIR)
project--write-project-list()
project-any-command(&optional OVERRIDING-MAP PROMPT-FORMAT)
project-async-shell-command()
project-buffers(PROJECT)
project-change-to-matching-directory(CURRENT-PROJECT MIRROR-PROJECT)
project-combine-directories(&rest LISTS-OF-DIRS)
project-compile()
project-current(&optional MAYBE-PROMPT DIRECTORY)
project-customize-dirlocals()
project-dired()
project-display-buffer(BUFFER-OR-NAME)
project-display-buffer-other-frame(BUFFER-OR-NAME)
project-eshell()
project-execute-extended-command()
project-external-roots(PROJECT)
project-files(PROJECT &optional DIRS)
project-find-dir()
project-find-file(&optional INCLUDE-ALL)
project-find-file-in(SUGGESTED-FILENAME DIRS PROJECT &optional INCLUDE-ALL)
project-find-matching-buffer()
project-find-matching-file-or-directory(CURRENT-PROJECT MIRROR-PROJECT)
project-find-regexp(REGEXP)
project-forget-project(PROJECT-ROOT)
project-forget-projects-under(DIR &optional RECURSIVE)
project-forget-zombie-projects(&optional INTERACTIVE)
project-ignores(PROJECT DIR)
project-kill-buffers(&optional NO-CONFIRM PROJECT)
project-known-project-roots()
project-list-buffers(&optional ARG)
project-list-buffers-buffer-menu(PROJECT &optional FILES-ONLY)
project-list-buffers-ibuffer(PROJECT &optional FILES-ONLY)
project-mode-line-format()
project-name(PROJECT)
project-or-external-find-file(&optional INCLUDE-ALL)
project-or-external-find-regexp(REGEXP)
project-other-frame-command()
project-other-tab-command()
project-other-window-command()
project-prefix-or-any-command()
project-prefixed-buffer-name(MODE)
project-prompt-project-dir(&optional PROMPT PREDICATE REQUIRE-KNOWN ALLOW-EMPTY)
project-prompt-project-name(&optional PROMPT PREDICATE REQUIRE-KNOWN ALLOW-EMPTY)
project-prune-zombies-default(PROJECT)
project-query-replace-regexp(FROM TO)
project-read-project()
project-recompile(&optional EDIT-COMMAND)
project-remember-project(PR &optional NO-WRITE STABLE)
project-remember-projects-under(DIR &optional RECURSIVE)
project-root(PROJECT)
project-root-find-file(FILENAME)
project-roots(PROJECT)
project-save-some-buffers(ARG)
project-search(REGEXP)
project-shell()
project-shell-command()
project-subtract-directories(FILES DIRS)
project-switch-project(DIR)
project-switch-to-buffer(BUFFER-OR-NAME)
project-try-vc(DIR)
project-try-vc--search(DIR)
project-uniquify-dirname-transform(DIRNAME)
project-vc-dir()
vc-git-project-list-files(DIR EXTRA-IGNORES)
vc-hg-project-list-files(DIR EXTRA-IGNORES)

Defined faces (0)