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

global, enh: add function for global to update single file #165

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions citre-global.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ database in the project directory."

;;;;; Internals

(declare-function tramp-file-name-localname "tramp" (structure))
(declare-function tramp-dissect-file-name "tramp" (name &optional nodefault))
(declare-function tramp-handle-expand-file-name "tramp" (name &optional dir))

(defun citre-global--get-output-lines (args)
"Get output from global program.
ARGS is the arguments passed to the program."
Expand Down Expand Up @@ -113,12 +109,10 @@ START-FILE."
(_ (error "Invalid MODE")))
(when case-fold (push "--ignore-case" cmd))
;; Global doesn't know how to expand "~", so we need to expand START-FILE.
(when start-file (let ((file (if (file-remote-p start-file)
(tramp-file-name-localname
(tramp-dissect-file-name
(tramp-handle-expand-file-name
start-file)))
(expand-file-name start-file))))
(when start-file (let* ((filename (expand-file-name start-file))
(file (if (file-remote-p start-file)
(file-local-name filename)
filename)))
(push (concat "--nearness=" file) cmd)))
(setq cmd (append (nreverse cmd)
(list "--color=never"
Expand Down Expand Up @@ -338,6 +332,38 @@ See *citre-global-update* buffer" s))))
:file-handler t)
(message "Updating...")))

;;;###autoload
(defun citre-global-update-file (&optional f)
"Update the gtags database of a single file F.
If no database is found, prompt the user to create one."
(interactive)
(let* ((prog (or citre-global-program "global"))
(filename (expand-file-name (or f (buffer-file-name))))
(file (if (file-remote-p filename)
(file-local-name filename)
filename)))
(make-process
:name "global"
:buffer (get-buffer-create "*citre-global-update-file*")
:command (list prog "--single-update" file)
:connection-type 'pipe
:stderr nil
:sentinel
(lambda (proc _msg)
(pcase (process-status proc)
('exit
(pcase (process-exit-status proc)
(0 (message "Finished updating file \"%s\"" file))
(_ (if (citre-executable-find prog t)
(when (y-or-n-p "Can't find database. Create one? ")
(citre-global-create-database))
(user-error "Can't find global program")))))
(s (user-error "Abnormal status of global: %s. \
See *citre-global-update-file* buffer" s))))
:file-handler t)
(message "Updating file \"%s\"..." file)))


;;;; Get identifiers

(defun citre-global-get-identifiers ()
Expand Down
Loading