My lightweight configuration

Hello everyone,

here is my configuration, hopefully serves as a good inspiration :slight_smile:

(setf *socket-path* nil) ;; allow multiple instances of Nyxt

(define-configuration browser
    ((session-restore-prompt :never-restore)
     (startup-function (make-startup-function :buffer-fn (lambda () (make-buffer :url "about:blank"))))))

(define-configuration web-buffer
    ((default-modes (append '(auto-mode emacs-mode) %slot-default))
     (override-map (let ((map (make-keymap "my-override-map")))
                     (define-key map
                       "C-q" 'quit
                       "C-1" 'make-window
                       "C-2" 'delete-current-window)
                     map))))

(define-configuration buffer
    ((default-modes (append '(emacs-mode) %slot-default))
     (override-map (let ((map (make-keymap "my-override-map")))
                     (define-key map
                       "C-q" 'quit
                       "C-1" 'make-window
                       "C-2" 'delete-current-window)
                     map))))

 (define-configuration nyxt/auto-mode:auto-mode
   ((nyxt/auto-mode:prompt-on-mode-toggle t)))

(defvar +dev-data-profile+ (make-instance 'data-profile :name "dev")
  "Development profile.")

(defmethod nyxt:expand-data-path ((profile (eql +dev-data-profile+)) (path data-path))
  "Persist data to /tmp/nyxt/."
  (expand-default-path (make-instance (class-name (class-of path))
                                      :basename (basename path)
                                      :dirname "/tmp/nyxt/")))

#+darwin
(define-command cpu-sleep ()
  "Put the computer to sleep."
  (uiop:run-program "/Users/jmercouris/User/cpu_sleep"))

#+darwin
(define-command cpu-battery ()
  "Show the battery status."
  (echo (uiop:run-program "/Users/jmercouris/User/cpu_battery" :output :string)))

#+darwin
(define-command open-in-safari ()
  "Open the current URL in Safari"
  (uiop:run-program (list "open" "-a" "Safari" (object-string (url (current-buffer))))))

5 Likes

Addendum (auto-config.lisp):

(DEFINE-CONFIGURATION BUFFER
  ((HINTS-ALPHABET "asfdghjkl")))
2 Likes

Here is my latest configuration:

(define-configuration browser
  ((session-restore-prompt :never-restore)
   (autofills (list (make-autofill :key "Current time"
                                   :fill (lambda () (format nil "~a" (local-time:now))))))))

(define-configuration nyxt/auto-mode:auto-mode
  ((nyxt/auto-mode:prompt-on-mode-toggle t)))

(define-configuration buffer
  ((default-modes (append '(emacs-mode) %slot-default%))
   (override-map (let ((map (make-keymap "my-override-map")))
                   (define-key map
                     "C-q" 'quit
                     "C-1" 'make-window
                     "C-2" 'delete-current-window
                     "keypadleft" 'nyxt/web-mode:history-backwards
                     "keypadright" 'nyxt/web-mode:history-forwards)
                   map))))

(define-configuration web-buffer
  ((default-modes (append '(emacs-mode blocker-mode) %slot-default%))
   (password-interface (make-instance 'password:password-store-interface))))

(define-configuration (prompt-buffer)
    ((default-modes (append '(emacs-mode) %slot-default%))
     (hide-suggestion-count-p t)))

(define-configuration status-buffer
    ((style (str:concat 
             %slot-default%
             (cl-css:css
              '(("#container"
                 ;; Columns: controls, arrow, url
                 :grid-template-columns "115px 10px 1fr")))))))

(define-configuration nyxt/web-mode::web-mode
  ((nyxt/web-mode::hints-alphabet "asdfghjklqwertyuiop")))

(define-command-global current-time ()
  "Show the current time."
  (echo "~a" (local-time:now)))

(defmethod nyxt::startup ((browser browser) urls)
  "Make a blank buffer."
  (window-make browser)
  (let ((window (current-window)))
    (window-set-buffer window (make-buffer :url (quri:uri "about:blank")))
    (toggle-fullscreen window)))

#+darwin
(define-command cpu-sleep ()
  "Put the computer to sleep."
  (uiop:run-program "/Users/jmercouris/User/cpu_sleep"))

#+darwin
(define-command cpu-battery ()
  "Show the battery status."
  (echo (uiop:run-program "/Users/jmercouris/User/cpu_battery" :output :string)))

#+darwin
(define-command open-in-safari ()
  "Open the current URL in Safari"
  (uiop:run-program (list "open" "-a" "Safari" (object-string (url (current-buffer))))))

Again updated to reflect the latest changes:

(define-configuration browser
  ((session-restore-prompt :never-restore)
   (autofills (list (make-autofill :key "Current time"
                                   :fill (lambda () (format nil "~a" (local-time:now))))))))

(define-configuration nyxt/auto-mode:auto-mode
  ((nyxt/auto-mode:prompt-on-mode-toggle t)))

(define-configuration buffer
  ((default-modes (append '(emacs-mode) %slot-default%))
   (override-map (let ((map (make-keymap "my-override-map")))
                   (define-key map
                     "C-q" 'quit
                     "C-1" 'make-window
                     "C-2" 'delete-current-window
                     "keypadleft" 'nyxt/web-mode:history-backwards
                     "keypadright" 'nyxt/web-mode:history-forwards)
                   map))))

(define-configuration web-buffer
  ((default-modes (append '(emacs-mode blocker-mode) %slot-default%))
   (password-interface (make-instance 'password:password-store-interface))))

(define-configuration (prompt-buffer)
    ((default-modes (append '(emacs-mode) %slot-default%))
     (hide-suggestion-count-p t)))

(define-configuration status-buffer
    ((style (str:concat 
             %slot-default%
             (cl-css:css
              '(("#container"
                 ;; Columns: controls, url
                 :grid-template-columns "120px 2fr")))))))

(defun my-format-status (window)
  (let ((buffer (current-buffer window)))
    (markup:markup
     (:div :id "container"
           (:div :id "controls" :class "arrow-right"
                 (markup:raw (format-status-buttons)))
           (:div :id "url"
                 (markup:raw
                  (format-status-load-status buffer)
                  (format-status-url buffer)))))))

(define-configuration window
  ((status-formatter #'my-format-status)))

(define-configuration nyxt/web-mode::web-mode
  ((nyxt/web-mode::hints-alphabet "asdfghjklqwertyuiop")))

(define-command-global current-time ()
  "Show the current time."
  (echo "~a" (local-time:now)))

(defmethod nyxt::startup ((browser browser) urls)
  "Make a blank buffer."
  (window-make browser)
  (let ((window (current-window)))
    (window-set-buffer window (make-buffer :url (quri:uri "about:blank")))
    (toggle-fullscreen window)))

#+darwin
(define-command cpu-sleep ()
  "Put the computer to sleep."
  (uiop:run-program "/Users/jmercouris/User/cpu_sleep"))

#+darwin
(define-command cpu-battery ()
  "Show the battery status."
  (echo (uiop:run-program "/Users/jmercouris/User/cpu_battery" :output :string)))

#+darwin
(define-command open-in-safari ()
  "Open the current URL in Safari"
  (uiop:run-program (list "open" "-a" "Safari" (object-string (url (current-buffer))))))
2 Likes

object-string doesn’t work anymore, replace with quri:render-uri ?

Ah, you mean for the safari directive, you are correct. However on macOS I have an older version of Nyxt!

My latest latest config:

(setf *socket-path* nil)

(asdf:load-system :demeter)
(asdf:load-system :nx-fruit)

(define-configuration browser
  ((session-restore-prompt :always-restore)))

(define-command-global hello (world)
  "Print something"
  (echo world))

(define-configuration nyxt/auto-mode:auto-mode
    ((nyxt/auto-mode:prompt-on-mode-toggle t)))

(define-configuration buffer
    ((default-modes (append '(emacs-mode) %slot-default%))
     (override-map (let ((map (make-keymap "my-override-map")))
                     (define-key map
                       "M-space" 'execute-command
                       "C-q" 'quit
                       "C-1" 'make-window
                       "C-2" 'delete-current-window
                       "keypadleft" 'nyxt/web-mode:history-backwards
                       "keypadright" 'nyxt/web-mode:history-forwards
                       "keypadbegin" 'reload-current-buffer)
                     map))))

(define-configuration web-buffer
    ((default-modes (append '(emacs-mode blocker-mode) %slot-default%))
     (password-interface (make-instance 'password:password-store-interface))))

(define-configuration (prompt-buffer)
    ((default-modes (append '(emacs-mode) %slot-default%))
     (hide-suggestion-count-p t)))

(define-configuration (nyxt/blocker-mode:blocker-mode)
    ((glyph "⦸")))
(define-configuration (nyxt/emacs-mode:emacs-mode)
    ((glyph "⊹")))
(define-configuration (nyxt/certificate-exception-mode:certificate-exception-mode)
    ((glyph "⇢")))
(define-configuration (nyxt/web-mode:web-mode)
    ((glyph "🖧")))

(define-configuration status-buffer
    ((glyph-mode-presentation-p t)
     (style (str:concat 
             %slot-default%
             (cl-css:css
              '(("*"
                 :background-color "rgb(100,100,100) !important")
                (".arrow-right"
                 :clip-path "none")))))))

(define-configuration window
    ((prompt-buffer-open-height 300)))

(define-configuration nyxt/web-mode::web-mode
    ((nyxt/web-mode::hints-alphabet "asdfghjklqwertyuiop")))

(define-command-global current-time ()
  "Show the current time."
  (echo "~a" (local-time:now)))

(defmethod nyxt::startup ((browser browser) urls)
  "Make a blank buffer."
  (window-make browser)
  (let ((window (current-window))
        (buffer (make-buffer :url (quri:uri "about:blank"))))
    (window-set-buffer window buffer)
    ;; (toggle-fullscreen window)
    ))

#+darwin
(define-command cpu-sleep ()
  "Put the computer to sleep."
  (uiop:run-program "/Users/jmercouris/User/cpu_sleep"))

#+darwin
(define-command cpu-battery ()
  "Show the battery status."
  (echo (uiop:run-program "/Users/jmercouris/User/cpu_battery" :output :string)))

#+darwin
(define-command open-in-safari ()
  "Open the current URL in Safari"
  (uiop:run-program (list "open" "-a" "Safari" (object-string (url (current-buffer))))))

(define-command-global open-in-firefox ()
  "Open the current URL in Firefox"
  (uiop:run-program (list "firefox" (render-url (url (current-buffer))))))

(define-bookmarklet-command snake
  "Play snake"
  "javascript:for(
  Q=128,/*maze size*/
  m=b=Q*Q,
  a=[P=l=u=d=p=S=w=0],/*a=grid,P=playing,l=food-iters left (until tail starts moving),u=food age,d=dir,p=prev-dir,S=score,w=score to be added on,m=the score to be added if food was eaten now*/
  u=89,
  f=(h=j=t=(b+Q)/2)-1,/*f=food,h=head,j=prev-head,t=tail. set food to left so gets picked up immediately, setting initial snake size*/
  (B=(D=document).body).appendChild(x=D.createElement('p')),(X=x.style).position='fixed',X.left=X.top=0,X.background='#FFF',x.innerHTML='<p></p><canvas>',
  v=(s=x.childNodes)[0],(s=s[1]).width=s.height=Q*5,c=s.getContext('2d'),
  onkeydown=onblur=F=function(e,z){
  z? /*calc food*/
  a[f]?(
  w+=m,/*aging food score calc*/
  f=Math.random(l+=8)*(R=Q-2)*R|(u=0),F(f+=Q+1+(f/R|0)*2,z)/*random (re)calc food loc*/
  ):F(f)/*draw food*/
  :e<0?( /*iter*/
  l?--l:(y=t,t=a[t]-2,F(y)),/*set tail*/
  S+=(w*=.8)/4,/*pretty score up*/
  m=999/(u+++10),/*age food a bit*/
  a[h+=[-1,-Q,1,Q][d=p]]?/*collision detect*/
  B.removeChild(x,alert('Game Over')):
  (F(h),/*draw head*/
  F(e,j=h),/*calc food*/
  v.innerHTML=P?(setTimeout(F,50,e,0),S|0):'Press P')/*next iter*/
  ):-e?(/*draw (+recalc sqr)*/
  y=(a[e]=
  e<Q|e>=Q*Q-Q|/*tb walls*/
  !(e%Q)|e%Q==Q-1|/*lr walls*/
  (e==h)*2)/*snake head*/
  +(e==f),
  e==h&&(a[j]=2+h),/*snake chain*/
  c.fillStyle='hsl('+!a[e]*99+','+m*2+'%,'+y*50+'%)',/*color calc*/
  c.fillRect(e%Q*5,(e/Q|0)*5,5,5)
  ):/*keyinput*/
  isNaN(y=e.keyCode-37)|y==43?
  (P=y&&!P)&&F(-1)/*pause*/
  :p=
  !P|y&-4|!(y^2^d)?/*arrow keys&&not directly opposite*/
  p:y;
  return!1
  };--b;F(b));/*init grid*/
  void F(-1)/*dummy update*/")

;; Disable Compositing for Nvidia driver
;; (setf (uiop:getenv "WEBKIT_DISABLE_COMPOSITING_MODE") "1")

1 Like

Great! Thanks for sharing.

1 Like