Browse Source

Merge 7128f341ef into 3e3a3d275c

pull/4/merge
Ritesh Agarwal 7 months ago
committed by GitHub
parent
commit
1552f5d5f4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 68
      opengrok-restful.el

68
opengrok-restful.el

@ -54,18 +54,39 @@
(defun opengrok-restful-current-line ()
(buffer-substring-no-properties (line-beginning-position) (line-end-position)))
(defun opengrok-restful-get-file-content (path)
(let ((content nil)
(download-url (format "%s/raw%s"
(s-replace "/api/v1/search" "" opengrok-restful-url)
path)))
(request download-url
:type "GET"
:headers (list (cons "Authorization" (format "Bearer %s" opengrok-restful-token)))
:parser 'buffer-string
:sync t
:complete (cl-function (lambda (&key data &allow-other-keys)
(setq content data))))
content))
(defun opengrok-restful-jump-to-target (line-content)
(cl-multiple-value-bind (path linum)
(save-match-data
(string-match "/.+:[0-9]+" line-content)
(split-string (match-string 0 line-content) ":"))
(find-file (concat
(file-name-as-directory opengrok-restful-source-directory)
(let ((content (opengrok-restful-get-file-content path)))
(when content
(let* ((full-path (concat (file-name-as-directory opengrok-restful-source-directory)
(substring path 1)))
(buffer (generate-new-buffer (file-name-nondirectory full-path))))
(switch-to-buffer-other-window buffer)
(with-current-buffer buffer
(erase-buffer)
(insert content)
(setq buffer-file-name full-path)
(set-auto-mode)
(goto-char (point-min))
(forward-line (1- (string-to-number linum)))
(kill-buffer opengrok-restful-buffer)
))
(forward-line (1- (string-to-number linum))))
)))))
(setq opengrok-restful-keymap
(let ((map (make-sparse-keymap)))
@ -79,11 +100,19 @@
(kill-buffer (current-buffer))))
map))
(defun opengrok-restful-parse-response (data)
(defun opengrok-restful-parse-response (data project value)
(with-current-buffer (get-buffer-create opengrok-restful-buffer)
(setq buffer-read-only nil)
(erase-buffer)
(goto-char (point-max))
(if (> (point) (point-min))
(insert "\n\n"))
(let ((start-of-new-results (point)))
(insert "--- New Search Results ---\n")
(insert (format "Project: %s\n" (or project "all")))
(insert (format "Search: %s\n\n" value))
(opengrok-restful-mode)
(mapcar (lambda (file)
(let ((file-name (symbol-name (car file)))
(file-lines (cdr file)))
@ -100,10 +129,12 @@
(when (< 0 (buffer-size))
(progn
(switch-to-buffer-other-window opengrok-restful-buffer)
(goto-char (point-min))))
))
(goto-char start-of-new-results))))))
(defun opengrok-restful-project-lookup (request-params)
(let* ((project (cdr (assoc "projects" request-params)))
(search-pair (car (remove (assoc "projects" request-params) request-params)))
(value (cdr search-pair)))
(request opengrok-restful-url
:type "GET"
:params request-params
@ -111,13 +142,23 @@
:parser 'json-read
:sync t
:complete (cl-function (lambda (&key data &allow-other-keys)
(opengrok-restful-parse-response data)))))
(opengrok-restful-parse-response data project value))))))
(defvar opengrok-restful-current-project nil
"The current project name to use for OpenGrok searches.")
(defun opengrok-restful-set-current-project (project-name)
"Set the current OpenGrok project name."
(interactive "sProject name: ")
(setq opengrok-restful-current-project project-name)
(message "OpenGrok project set to: %s" project-name))
(defun opengrok-restful-current-project-name ()
(file-name-nondirectory (directory-file-name (projectile-project-root))))
"Return the current OpenGrok project name."
opengrok-restful-current-project)
(defun opengrok-restful-make-params (project type value)
(let ((params `((,type ,value))))
(let ((params `((,type . ,value))))
(if (not (string= "" project))
(cons `("projects" . ,(if (string= "c" project)
(opengrok-restful-current-project-name)
@ -135,8 +176,7 @@
(opengrok-restful-make-params
(read-string "Project> ")
,(symbol-name type)
(read-string (format "Symbol (%s)> " default-symbol) nil nil default-symbol)))
))))
(read-string (format "Symbol (%s)> " default-symbol) nil nil default-symbol)))))))
(opengrok-restful-define-lookup full)
(opengrok-restful-define-lookup def)

Loading…
Cancel
Save