dotfiles/emacs/.emacs.d/config/init-built-ins.el
Jeremy Dormitzer f3353bb124 Add eww configuration and custom URL prompt function
This commit adds configuration for the built-in `eww` web browser in Emacs. It introduces a custom prompting function that suggests URLs or keywords based on the browsing history, current URL, and other suggestions, enhancing the user experience. Additionally, a key binding for the `eww` function is added in `eww-mode-map`.
2024-07-23 11:00:57 -04:00

99 lines
2.7 KiB
EmacsLisp

;; -*- lexical-binding: t; -*-
;; Configuration for built-ins that don't fit anywhere else
(use-package custom
:straight (:type built-in)
:defer t)
(use-package view
:straight (:type built-in)
:defer t
:config
(evil-collection-define-key 'normal 'view-mode-map
"0" 'evil-beginning-of-line
"g0" 'text-scale-adjust))
(use-package simple
:straight (:type built-in)
:general
(leader-map "!" #'shell-command
"|" #'shell-command-on-region
";" #'async-shell-command)
(normal special-mode-map
"gr" #'revert-buffer
"q" #'quit-window)
(normal messages-buffer-mode-map
"gr" #'revert-buffer
"q" #'quit-window))
(use-package shell
:straight (:type built-in)
:general
(normal shell-mode-map "q" #'quit-window))
(use-package ediff
:defer t
:straight (:type built-in)
:config
(setq ediff-window-setup-function #'ediff-setup-windows-plain)
;; Restore window configuration after an ediff session
(defvar ediff-last-windows nil)
(defun store-pre-ediff-winconfig ()
(setq ediff-last-windows (current-window-configuration)))
(defun restore-pre-ediff-winconfig ()
(set-window-configuration ediff-last-windows))
(add-hook 'ediff-before-setup-hook #'store-pre-ediff-winconfig)
(add-hook 'ediff-quit-hook #'restore-pre-ediff-winconfig))
(use-package replace
:defer t
:straight (:type built-in))
(use-package man
:straight (:type built-in)
:commands (man)
:custom
(manual-program "gman"))
(use-package re-builder
:straight (:type built-in)
:commands (re-builder)
:custom
(reb-re-syntax 'string))
(use-package hippie-expand
:straight (:type built-in)
:general
([remap dabbrev-expand] #'hippie-expand))
(use-package browse-url
:straight (:type built-in)
:config
(defun browse-url-or-search (url-or-symbol)
"If URL-OR-SYMBOL is a URL, browse it. Otherwise, search for it."
(interactive (list (thing-at-point 'symbol)))
(if (ffap-url-p url-or-symbol)
(browse-url url-or-symbol)
(browse-url (format "https://www.google.com/search?q=%s" url-or-symbol)))))
(use-package eww
:straight (:type built-in)
:config
(defun eww-before-advice (&rest args)
(interactive
(let* ((uris (eww-suggested-uris))
(browser-history (mapcar (lambda (h) (plist-get h :url)) eww-history))
(suggestions (delete-dups (append uris eww-prompt-history browser-history)))
(current-uri (plist-get eww-data :url)))
(list (completing-read "URL or keywords: " suggestions nil nil current-uri 'eww-prompt-history)
current-prefix-arg))))
(advice-add 'eww :before #'eww-before-advice)
:general
(normal eww-mode-map "go" #'eww))
(provide 'init-built-ins)