Skip to content

Commit

Permalink
Adding variable to define Custom browser to use (#18)
Browse files Browse the repository at this point in the history
Added custom variable `grip-url-browser` to specify another browser to
be used instead of default one, and `grip-url-args` to pass to 
`grip-url-browser`.

Added function grip--browser which will load preview either by using
grip-url-browser or default browser
  • Loading branch information
shubham-cpp authored May 15, 2021
1 parent 31e72e7 commit 02b7a81
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ Run `M-x customize-group RET grip RET` or set the variables.
;; Path to the grip binary
(setq grip-binary-path "/path/to/grip")
;; You can use this variable to define another browser
;; to use when loading previews. By default this value is `nil`
;; meaning use default browser defined by your system
(setq grip-url-browser "custom_browser")
;; If you want to pass arguements to your custom browser then use
(setq grip-url-args '("arg1" "arg2" "etc"))
;; A GitHub username for API authentication
(setq grip-github-user "")
Expand Down
24 changes: 22 additions & 2 deletions grip-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
:type 'file
:group 'grip)

(defcustom grip-url-browser nil
"Browser to launch Markdown/Org previews.
Use default browser if nil."
:type '(choice (const :tag "None" nil) string)
:group 'grip)

(defcustom grip-url-args nil
"A list of strings defining options for `grip-url-browser'."
:type '(repeat (string :tag "Argument")))

(defcustom grip-github-user ""
"A GitHub username for API authentication."
:type 'string
Expand All @@ -81,7 +91,6 @@ option."
:type 'boolean
:group 'grip)



;; Externals
(declare-function xwidget-buffer 'xwidget)
Expand All @@ -98,6 +107,17 @@ option."
(defvar-local grip--preview-file nil
"The preview file for grip process.")

(defun grip--browser (url)
"Use browser specified by user to load URL.
Use default browser if nil."
(if grip-url-browser
(let ((browse-url-generic-program grip-url-browser)
(browse-url-generic-args grip-url-args))
(ignore browse-url-generic-program)
(ignore browse-url-generic-args)
(browse-url-generic url))
(browse-url url)))

(defun grip--browse-url (url)
"Ask the browser to load URL.
Expand All @@ -110,7 +130,7 @@ Use default browser unless `xwidget' is available."
(when (buffer-live-p buf)
(and (eq buf (current-buffer)) (quit-window))
(pop-to-buffer buf))))
(browse-url url)))
(grip--browser url)))

(defun grip--preview-url ()
"Return grip preview url."
Expand Down

0 comments on commit 02b7a81

Please sign in to comment.