Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to configure a title extractor per file extension #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Sep 11, 2021

  1. Added support to configure a parser per file extension

    Before this update, Deft used the first line of a file and the
    function bound to deft-parse-title-function to obtain the file title
    to be displayed.
    
    This update renames deft-parse-title-function to
    deft-parse-title-functions.  The variable is not bound anymore to a
    function used to parse the first line of the files.  It is now an
    alist that defines the parsers used per file extension.  The previous
    default parser (deft-strip-title) is maintained as the default
    parser.  It is associated with :default in the alist.
    
    An example of an .emacs configuration to use Deft and Org-Roam to
    maintain titles different from filenames includes:
    
    (defun my-deft-org-title (contents)
      "Look for the title in the first 500 characters of an org file.
    This function looks for the TITLE property in the first 500
    characters of CONTENTS."
      (let ((prelude (substring contents 0 (min (length contents) 500))))
        (when prelude
          (let ((title (substring prelude (string-match "^#\\+TITLE:.+$" prelude) (match-end 0))))
            (deft-chomp (replace-regexp-in-string "^#\\+TITLE:" ""
    	title))))))
    
    (setq deft-parse-title-functions (push '("org" . my-deft-org-title) deft-parse-title-functions))
    andresm committed Sep 11, 2021
    Configuration menu
    Copy the full SHA
    ed626c5 View commit details
    Browse the repository at this point in the history