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

Feature: consistent zk-link-format and POSIX regexp conversion for grep #68

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Commits on Jul 15, 2023

  1. Update format-related docstrings for consistency/helpfulness

    * `zk-format-function`'s docstring pointed to a very sparse `zk--format`
      docstring.
    
    * Other `*-format` variables had wrong information (`zk-format-function` should
      never be nil) and repeated information that pertains properly only to
      `zk-format-id-and-title`.
    boyechko committed Jul 15, 2023
    Configuration menu
    Copy the full SHA
    b01a5bd View commit details
    Browse the repository at this point in the history
  2. Replace hardcoded title regexp with zk-title-regexp

    It's generally a good practice to avoid hardcoded values, but this also allows
    the user to customize what the title looks like.
    boyechko committed Jul 15, 2023
    Configuration menu
    Copy the full SHA
    b0790e0 View commit details
    Browse the repository at this point in the history
  3. Extend zk-link-regexp to take ID/title & generate targeted regexps

    Since `zk--grep-file-list` expects a regexp anyway, might as well use the
    `zk-link-regexp` to generate it rather than doing it locally and repeating code.
    boyechko committed Jul 15, 2023
    Configuration menu
    Copy the full SHA
    5c449bf View commit details
    Browse the repository at this point in the history
  4. Extend zk-link-regexp to capture same groups as zk-file-name-regexp

    This increases consistency, which should help to avoid obscure bugs.
    boyechko committed Jul 15, 2023
    Configuration menu
    Copy the full SHA
    5855ccc View commit details
    Browse the repository at this point in the history
  5. Change zk-link-format to use same %-sequences as other *-format vars

    Having consistent syntax is helpful to avoid mistakes. Additionally, this change
    allows 1) simplifying `zk--format` so it doesn't need to handle two different
    sets of %-sequences, and 2) experimenting with other link markup, such as
    `[[%i][%t]]` for org-mode links without explicit link type or `[[%i|%t]]` for
    syntax used by MediaWiki.
    boyechko committed Jul 15, 2023
    Configuration menu
    Copy the full SHA
    fd69c0b View commit details
    Browse the repository at this point in the history
  6. Fix bug with zk-backlinks; add zk--posix-regexp to sanitize regexps

    So far, functions like `zk--grep-file-list` have just passed Elisp-style regexp
    to `grep` and hoped it works, which it does for zk-ID or other literal strings.
    Changes to `zk-link-regexp` in PR localauthor#63 broke things because it introduced
    explicit capture groups (`\(?1:...\)`), which is not supported by POSIX regexps
    that `grep` uses.
    
    The new function, `zk--posix-regexp`, does some basic conversion from
    Elisp-style regexps to POSIX-style. There is package `pcre2el` that does it in a
    more complete and sophisticated way, but for our purposes, this should be
    enough.
    
    Functions that pass regexps to `grep`, such as `zk--grep-file-list`,
    `zk--grep-tag-list`, and `zk--grep-link-id-list` are updated to
    sanitize ("POSIXize") the regexps they pass. The cost is minuscule ("Elapsed
    time: 0.000379s" for 10,000 calls with a complex regexp).
    boyechko committed Jul 15, 2023
    Configuration menu
    Copy the full SHA
    7d3cce3 View commit details
    Browse the repository at this point in the history