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

rtags-cached-current-container request #792

Open
Nephyrin opened this issue Sep 10, 2016 · 0 comments
Open

rtags-cached-current-container request #792

Nephyrin opened this issue Sep 10, 2016 · 0 comments

Comments

@Nephyrin
Copy link

Nephyrin commented Sep 10, 2016

I've been using the container tracking to provide a much-improved which-func-mode, but I ended up with quite a mess to get the data I need from it:

  • There's no way to easily tell if the cached current container is stale, so blindly sticking it in the modeline/headerline results in a stale value often.
  • It doesn't contain fontification, which bothers me more than is reasonable.

The mess I ended up with attempting to solve this uses rtags-current-container-hook to call rtags-current-container, use my poor grasp of elisp to brutalize the data I need to substring the actual container from the fontified buffer, and store a range for which it is valid:

(setq rtags-current-container-hook (lambda (containerName)
                                     (let* ((container       (rtags-current-container))
                                            (startLineCell   (when container (assoc 'startLine container)))
                                            (endLineCell     (when container (assoc 'endLine container)))
                                            (startColumnCell (when container (assoc 'startColumn container)))
                                            (endColumnCell   (when container (assoc 'endColumn container)))
                                            (needed          (and container startLineCell endLineCell
                                                                  startColumnCell endColumnCell))
                                            (startLine       (when needed (cdr startLineCell)))
                                            (endLine         (when needed (cdr endLineCell)))
                                            (startColumn     (when needed (cdr startColumnCell)))
                                            (endColumn       (when needed (cdr endColumnCell)))
                                            (curLine         (when needed (line-number-at-pos)))
                                            (lineOffset      (when needed (- startLine curLine)))
                                            (endLineOffset   (when needed (- endLine curLine)))
                                            (charStart       (when needed (line-beginning-position (+ lineOffset 1))))
                                            (charEnd         (when needed (line-end-position (+ lineOffset 1))))
                                            (regionStart     (when needed (+ (line-beginning-position (+ lineOffset 1))
                                                                             startColumn)))
                                            (regionEnd       (when needed (+ (line-end-position (+ endLineOffset 1))
                                                                             endColumn)))
                                            (lineStr         (when (and needed charStart charEnd)
                                                               (buffer-substring charStart charEnd))))
                                       (setq neph-sticky-header
                                             (list
                                              (if lineStr lineStr (propertize "- unknown -" 'face 'neph-modeline-misc))))

                                       (setq neph-sticky-header-valid-range
                                             (if (and regionStart regionEnd)
                                                 (cons regionStart regionEnd)
                                               nil)))))

The header-line can then easily check if we have a pretty/fontified container name, and if our point is still roughly in that container:

(setq-default header-line-format
              '(:eval (when (and neph-sticky-header-valid-range
                                 (>= (point) (car neph-sticky-header-valid-range))
                                 (<= (point) (cdr neph-sticky-header-valid-range)))
                        neph-sticky-header)))

This would be a useful upstream feature, to provide, e.g., (rtags-get-cached-current-container &optional only_if_point_in_range).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants