Morgan Smith <[email protected]> writes:

> I have spent too many hours on this now.  The completion code is super
> confusing.
>
> Problems:
> 1. What is the name for the syntax described here:
>    [[info:org#Matching tags and properties]]
>    - In the code there are functions called
>      `org-make-tags-matcher', `org-match-sparse-tree', `org-tags-view'
>    - It is referred to as a "tags string", a "string with match
>      syntax", a "TAGS/TODO matcher", a "tags/property/todo match", a "tags
>      search"

Manual usually takes precedence in this regard.

>    - I'm going to stop searching here but just know there are probably a lot
>      more inconsistent references

That might be. These things evolved over time and the naming is not
always updated.

> 2. The function in question `org-tags-completion-function' is NOT a completion
>    function!  It's a completion table function and should probably be named in
>    a way consistent with other completion table functions.  Oh wait, they
>    aren't consistent at all... ugh.  I would probably go with
>    `org-tags-completion-table'.

Well. It is a completion function. See info node `21.6.7 Programmed
Completion' in Elisp manual, where such functions are called "completion
function".

> 4. How do I search for boundaries while ignoring quoted text?  I've read a lot
>    of syntax.c and I've come up with a "solution".  Basically I treat the 
> match
>    characters as open parenthesis and then ask Emacs to go back an sexp.  
> There
>    has got to be a better way right?
>
> #+begin_src elisp
> (let ((table (make-syntax-table))
>       (test-string "tag1+PROPERTY=\"+\""))
>   ;; The match symbols are open parenthesis
>   (mapc
>    (lambda (c)
>      (modify-syntax-entry c "(" table))
>    '(?- ?+ ?: ?& ?, ?|))
>   (with-temp-buffer
>     (with-syntax-table table
>       (insert test-string)
>       ;; This returns exactly what I want!
>       (scan-lists (point-max) -1 1) ; => 5
>       ;; But it doesn't handle unpaired quotes
>       (insert "\"")
>       (scan-lists (point-max) -1 1) ; => 16
>       )))
> #+end_src

org-make-tags-matcher simply uses "\"[^\"]*\"". It is not perfect, of
course, but the completion function should not be better than
org-make-tags-matcher

Otherwise, see info node `36.6 Parsing Expressions' in Elisp
manual. There is a dedicated machinery to detect whether we are inside a
string or not.

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to