Permalink
Fetching contributors…
Cannot retrieve contributors at this time
110 lines (89 sloc) 3.51 KB

Next EXTension Exposé

This Document is a place for users of Next to share useful customizations as a community. If you have something you wish to add, please feel free to open a PR with your customization.

Contents

Setting the start page

Setting the start page can easily be achieved in the following manner:

(setf *start-page-url* "about:blank")

Creating your own Parenscript

You can call any parenscript within the browser through the convient defparen, and defparenstatic macros. A really simple example below shows how you could set the body with the URL of the current page.

(defparenstatic hello-url
    (defun set-body (text)
      (setf (ps:chain document body inner-text) text)
      ;; return nil to avoid json decode errors
      nil)
  (set-body (ps:chain document -u-r-l)))

Defparenstatic will automatically generate a defparameter named hello-url as in the case above, and a function (hello-url) that you can invoke to act upon the currently *active-buffer*.

Running shell commands within Next

Shell mode is an extension for running simple one liner shell commands and seeing the output. There is no history or variables. Use C-x s to enter *shell-mode* and c to enter a command and k to clear the command output.

(defvar *shell-mode-map* (make-hash-table :test 'equalp))

(defclass shell-mode (mode) ())

(defun shell-mode ()
  (make-instance 'application-mode
		 :name "shell-mode"
		 :keymap *shell-mode-map*))

(defparenstatic clear-shell-output
    (setf (ps:chain document body inner-h-t-m-l) ""))

(defparen append-output (output)
  (setf (ps:chain document body inner-h-t-m-l)
        (ps:chain document body inner-h-t-m-l
                  (concat (ps:lisp
                           (concatenate 'string output "<br />"))))))

(defun run-shell-command (input)
  (interface:web-view-execute
   (view *active-buffer*)
   (append-output
    (uiop:run-program input :force-shell t :output :string))))

(defun open-new-shell ()
  (set-visible-active-buffer
   (generate-new-buffer "*shell*" (shell-mode))))

(define-key *shell-mode-map* (kbd "c")
  (:input *minibuffer* run-shell-command))

(define-key *shell-mode-map* (kbd "k")
  #'clear-shell-output)

(define-key *global-map* (kbd "C-x s")
  #'open-new-shell)

Reloading the page

The following function provides a way to reload the current page.

;; Reload page with §
(defparenstatic reload-page
  (ps:chain location (reload)))
(define-key *global-map* (kbd "§") #'reload-page)

Scroll the page up and down by a screen

You can use the following functions to scroll the page up or down by one screen.

(defparenstatic scroll-page-down
    (ps:chain window (scroll-by 0 (ps:@ window inner-height))))
(defparenstatic scroll-page-up
  (ps:chain window (scroll-by 0 (- (ps:@ window inner-height)))))

;; bind the new functions
(define-key *global-map* (kbd "C-v") #'scroll-page-down)
(define-key *global-map* (kbd "M-v") #'scroll-page-up)