Pages
  • Homepage
  • Queztaz/Tech Inventory
  • Emacs/Emacs With BiDirectional Google Calendar Sync
  • Emacs/Setting up Mu4e and Multiple Gmail Accounts
  • Emacs/EWW Hacks
  • Linux/Creating an Offline Debian Mirror Repository
  • Linux/Migrate Wiki.js to Another Server
  • Linux/Adding Bitwarden to the Pinephone Pro
  • Pinebook Pro/Custom Kernel
  • Pinebook Pro/Keyboard Firmware Update
  • Pinebook Pro/Netbsd Installation
  • Pinebook Pro/Setting Up Zram
  • Pinebook Troubleshooting/Pro Common Issues
  • Pinebook Pro/Use NVME as Root
  • Pinebook Pro/Write to SPI Flash
  • Qemu/Chroot Into a Different Architecture
  • Qemu/Choot Into an Img File
  • Qemu/Mount Virtual Images
  • Qemu/Windows Xp Fix Smb Not Working
  • Qemu/Windows Xp Installation
  • Misc/Finding the Default Wireless Password to TG1672G Routers
  • Misc/Running Ollama Portably
  • Windows/Cloning a Bios Boot Drive to Disimilar Hardware with UEFI
  • Windows/Automatic CHKDSK Scans Using Powershell & Email Alerts
  • Windows/Creating a Decent Portable Terminal
  • Windows/Merging HyperV Snapshots With Powershell
  • Windows/Simulating Bad Blocks on NTFS Filesystems
  • Windows/Creating and Viewing a Storport on Windows Server
  • Mikrotik/Creating a Client to Site VPN With
  • Mikrotik/Securing Router With Firewall
  • Mikrotik Setup Dynamically Changing IP With No-IP Api
Homepage
  • Homepage
  • Queztaz/Tech Inventory
  • Emacs/Emacs With BiDirectional Google Calendar Sync
  • Emacs/Setting up Mu4e and Multiple Gmail Accounts
  • Emacs/EWW Hacks
  • Linux/Creating an Offline Debian Mirror Repository
  • Linux/Migrate Wiki.js to Another Server
  • Linux/Adding Bitwarden to the Pinephone Pro
  • Pinebook Pro/Custom Kernel
  • Pinebook Pro/Keyboard Firmware Update
  • Pinebook Pro/Netbsd Installation
  • Pinebook Pro/Setting Up Zram
  • Pinebook Troubleshooting/Pro Common Issues
  • Pinebook Pro/Use NVME as Root
  • Pinebook Pro/Write to SPI Flash
  • Qemu/Chroot Into a Different Architecture
  • Qemu/Choot Into an Img File
  • Qemu/Mount Virtual Images
  • Qemu/Windows Xp Fix Smb Not Working
  • Qemu/Windows Xp Installation
  • Misc/Finding the Default Wireless Password to TG1672G Routers
  • Misc/Running Ollama Portably
  • Windows/Cloning a Bios Boot Drive to Disimilar Hardware with UEFI
  • Windows/Automatic CHKDSK Scans Using Powershell & Email Alerts
  • Windows/Creating a Decent Portable Terminal
  • Windows/Merging HyperV Snapshots With Powershell
  • Windows/Simulating Bad Blocks on NTFS Filesystems
  • Windows/Creating and Viewing a Storport on Windows Server
  • Mikrotik/Creating a Client to Site VPN With
  • Mikrotik/Securing Router With Firewall
  • Mikrotik Setup Dynamically Changing IP With No-IP Api

Emacs/EWW Hacks

Table of content
  • Hack list
  • Simple Styling
  • Rename EWW Buffers to Website Names
  • Force EWW to open new buffers by default
  • Faster Searches
  • Search highlighted region
  • Redirect Reddit to Reddit.old
  • Quasi Default Web Browser
  • Open EWW at startup

Collection of emacs snippets to enhance the eww experience.

Hack list

Simple Styling

(setq browse-url-browser-function 'eww-browse-url) ; Use eww as the default browser
(setq shr-use-fonts  nil)  ; No special fonts
(setq shr-use-colors nil) ; No colours
(setq shr-indentation 4) ; Left-side margin
(setq shr-width 70) ; Fold text to 70 columns
(setq eww-search-prefix "https://google.com/search?q=") ; Use another engine for searching

Rename EWW Buffers to Website Names

(setq eww-auto-rename-buffer t)

Force EWW to open new buffers by default

Normally EWW only runs as a single buffer, similar to Eshell. This function will make a new EWW buffer by default instead of replacing the previous.

(use-package eww
  :ensure t
  :config
  (defun modi/force-new-eww-buffer (orig-fun &rest args)
    "When prefix argument is used, a new eww buffer will be created,
    regardless of whether the current buffer is in `eww-mode'."
    (if current-prefix-arg
          (with-temp-buffer
            (apply orig-fun args))
        (apply orig-fun args)))  
  (advice-add 'eww :around #'modi/force-new-eww-buffer)
  )

Faster Searches

This function will prompt you for a string and allow you to search for it using your favorite search engine. If the string is a url it'll open it up.

(defun my/is-url (string)
  "Checks if STRING is a valid URL."
  (let ((url-parts (url-generic-parse-url string)))
    (and url-parts (url-type url-parts))))

(defun my/eww-search (x)
  "Searches stuff in eww"
  (interactive "sSearch Query: ")
  (switch-to-buffer (generate-new-buffer "eww"))
  (eww-mode)
  (eww (concat "https://lite.duckduckgo.com/lite/?q=" (replace-regexp-in-string " " "+" x)))
  )

; Binding it using evil mode
(evil-define-key 'normal eww-mode-map "ss" 'my/eww-search)

Search highlighted region

Highlighting a url will open it using EWW. If you highlight text, it'll google the string instead.

  (defun my/eww-search-selected (start end)
    "Searches the selected text in EWW. If it's a URL, opens it directly. If not, searches Google."
    (interactive "r")
    (when (use-region-p)
      (let ((region (buffer-substring-no-properties start end)))
        (if (my/is-url region)
            (eww-browse-url region)
          (split-window-right)
          (balance-windows)
          (other-window 1)
          (let ((query (replace-regexp-in-string "\n" " " region)))
            (eww-browse-url (concat "https://www.google.com/search?q=" (url-hexify-string query))))))))
(define-key map (kbd "C-c s") 'my/eww-search-selected)

Redirect Reddit to Reddit.old

Self explanatory. I had to compile emacs 29.2 with libxml2 support to get it to work. The URL transformers function wasn't available with my package managers emacs version.

(defun eww-reddit-redirect(url)
  "Redirect reddit.com to old.reddit.com automatically."
  (replace-regexp-in-string "https://www.reddit.com" "https://old.reddit.com" url))

(setq eww-url-transformers '(eww-remove-tracking eww-reddit-redirect))

Quasi Default Web Browser

Have EWW act as a default web browser source

(defalias 'gk-urls-external-browser 'browse-url-xdg-open)

(defun gk-browse-url (&rest args)
  "Prompt for whether or not to browse with EWW, if no browse
with external browser."
  (apply
   (if (y-or-n-p "Browse with EWW? ")
	 'eww-browse-url
     #'gk-urls-external-browser)
   args))

(setq browse-url-browser-function #'gk-browse-url) 

Open EWW at startup

(defun my/open-eww-in-background()
  (switch-to-buffer (generate-new-buffer "eww"))
  (eww-mode)
  (eww "https://lite.duckduckgo.com/lite/")
  (switch-to-buffer "*scratch*")
  )

(my/open-eww-in-background)
PREVRANDOMNEXT