5.4 Creating Priors

The third type of entities you may find yourself wanting to create are priors. Creating a new prior type is similar to that of candidate generators and mappings: you will create a new prior template with p-search-prior-template-create and add it to the list p-search-prior-templates.

Function: p-search-prior-template-create

Create a new prior template with the given keyword arguments. The following properties are available:

:id symbol

The ID symbol of the prior template. This should be the symbol that you store the prior template in. This is required in order to create priors from preset structures.

:group string

The name of the transient menu group the prior should go in. Example of groups are “emacs”, “filesystem”, and “git”.

:transient-key-string key-string

The transient keys which should be pressed to create the prior. These keys will appear after that of the group’s keys (e.g. if the group is “filesystem”, it will have an f key to begin).

:input-spec spec-alist

The specification for the required inputs arguments.

:options-spec spec-alist

The specification for the options arguments.

:required-properties required-props-list

A list of the required property symbols needed for the prior to work. Recall that properties are defined via the p-search-def-property function (see Creating Documents). If there are no documents with the requested properties, this prior will not be available.

:initialize-function mapping-function

The function which is ran when the prior is created, which should result in a score being assigned to each document. This function takes one argument, the prior that the user created. The function should either create a process that will assign scores to documents or directly assign scores in the function itself.

When creating the initialization function for a new prior type, the following functions will be helpful:

Function: p-search-set-score prior doc-id p

Set the score of doc-id to p of a given prior. note: in order for this function to work properly, you need to ensure your current buffer is that of the p-search session. Calling this function in a temporary buffer or a process buffer won’t work properly.

You can set a default score for all documents not specified by passing in :default to doc-id.

Function: p-search-candidates-with-properties prop-list

Return a hashmap of document-id to document for each document in the system that has every property specified in prop-list. You can use this in conjunction with the functions maphash, p-search-document-property (to get the properties you’re interested in), and p-search-set-score to set the scores of the documents.

Function: p-search-calculate

Perform a re-calculation and re-display of the session buffer. This should be called after you have set the score for every document you’re interested in. Otherwise, the user would have to refresh the buffer to see the score updates.

Function: p-search-prior-arguments prior

Return the input/option arguments a user provided to the prior as an alist.

Function: p-search-unique-properties prop-id

For every candidate document in the system, return all unique values of the property prop-id.