From 3cad9fdaf63dcfa5ba2492e8ff42b1d1a28e540c Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Fri, 2 Sep 2022 16:08:58 -0700 Subject: [PATCH] Bug fixes! Addresses some compilation warnings and some linting errors. --- ha-capturing-notes.org | 2 +- ha-config.org | 45 ++++++++++++++++++------------------------ ha-org.org | 30 ++++------------------------ 3 files changed, 24 insertions(+), 53 deletions(-) diff --git a/ha-capturing-notes.org b/ha-capturing-notes.org index 2843fa0..53611bf 100644 --- a/ha-capturing-notes.org +++ b/ha-capturing-notes.org @@ -197,7 +197,7 @@ Using =emacsclient=, the operating system or other applications can trigger a ca ;; (toggle-frame-fullscreen)) (delete-other-windows) - (flet ((switch-to-buffer-other-window (buf) (switch-to-buffer buf))) + (cl-flet ((switch-to-buffer-other-window (buf) (switch-to-buffer buf))) (org-capture))) (defadvice org-capture-finalize diff --git a/ha-config.org b/ha-config.org index ee212f3..46335ba 100644 --- a/ha-config.org +++ b/ha-config.org @@ -24,13 +24,12 @@ A literate programming file for configuring Emacs. ;;; Code: #+end_src * Basic Configuration -I hate a fat-finger that stop Emacs: +I begin with configuration of Emacs that isn’t /package-specific/. For instance, I hate a fat-finger that stop Emacs: #+begin_src emacs-lisp (setq confirm-kill-emacs 'yes-or-no-p) #+end_src New way to display line-numbers. I set mine to =relative= so that I can jump up and down by that value. Set this to =nil= to turn off, or =t= to be absolute. - #+begin_src emacs-lisp (setq display-line-numbers t display-line-numbers-type 'relative) @@ -38,7 +37,7 @@ New way to display line-numbers. I set mine to =relative= so that I can jump up I like the rendering to curved quotes using [[help:text-quoting-style][text-quoting-style]], because it improves the readability of documentation strings in the =∗Help∗= buffer and whatnot. #+begin_src emacs-lisp -(setq text-quoting-style 'curve) + (setq text-quoting-style 'curve) #+end_src Changes and settings I like introduced in Emacs 28: @@ -49,7 +48,6 @@ Changes and settings I like introduced in Emacs 28: #+end_src As [[https://tecosaur.github.io/emacs-config/config.html][tec wrote]], I want to use =~/.authsource.gpg= as I don’t want to accidentaly purge this file cleaning =~/.emacs.d=, and let's cache as much as possible, as my home machine is pretty safe, and my laptop is shutdown a lot. Also, as [[https://www.bytedude.com/gpg-in-emacs/][bytedude]] mentions, I need to se the =epa-pineentry-mode= to =loopback= to actually get a prompt for the password, instead of an error. - #+begin_src emacs-lisp (use-package epa-file :config @@ -60,11 +58,15 @@ As [[https://tecosaur.github.io/emacs-config/config.html][tec wrote]], I want to auth-source-cache-expiry nil)) #+end_src +Unicode ellispis are nicer than three dots: +#+begin_src emacs-lisp + (setq truncate-string-ellipsis "…") +#+end_src More settings: +When I get an error, I need a stack trace to figure out the problem. Yeah, when I stop fiddling with Emacs, this should go off: #+begin_src emacs-lisp - (setq truncate-string-ellipsis "…" ; Unicode ellispis are nicer than "..." - debug-on-error t) + (setq debug-on-error t) #+end_src The venerable [[help:hippie-expand][hippie-expand]] function does a better job than the default, [[help:dabbrev-expand][dabbrev-expand]], so let’s swap it out (see this [[https://www.masteringemacs.org/article/text-expansion-hippie-expand][essay]] by Mickey Petersen): @@ -123,12 +125,7 @@ Seems the best [[https://github.com/hlissner/doom-snippets][collection of snippe #+begin_src emacs-lisp (use-package doom-snippets :after yasnippet - :straight (:host github :repo "doomemacs/snippets") - :config - (add-to-list 'yas-snippet-dirs (thread-last user-emacs-directory - (expand-file-name "straight") - (expand-file-name "repos") - (expand-file-name "doom-snippets")))) + :straight (:host github :repo "doomemacs/snippets")) #+end_src *Note:* Including his snippets also includes some [[https://github.com/hlissner/doom-snippets#snippets-api][helper functions]] and other features. ** Auto Insert Templates @@ -832,27 +829,17 @@ Install the [[https://github.com/dajva/rg.el][rg]] package, which builds on the #+begin_src emacs-lisp (use-package rg - :general (:states 'normal "gr" 'rg-dwim) - :config + ;; In case I call (or something else) calls `grep': + (grep-apply-setting 'grep-command "rg") ; -n -H --no-heading -e + ;; Make an interesting Magit-like menu of options, which I don't use much: (rg-enable-default-bindings (kbd "M-R")) - ;; In case I call (or something else) calls `grep': - (grep-apply-setting 'grep-command "rg -n -H --no-heading -e ") ;; Old habits die hard ... (define-key global-map [remap xref-find-references] 'rg-dwim) - (advice-add 'wgrep-change-to-wgrep-mode :after #'evil-normal-state) - (advice-add 'wgrep-to-original-mode :after #'evil-motion-state) - (defvar rg-mode-map) - (add-to-list 'evil-motion-state-modes 'rg-mode) - (evil-add-hjkl-bindings rg-mode-map 'motion - "e" #'wgrep-change-to-wgrep-mode - "g" #'rg-recompile - "t" #'rg-rerun-change-literal) - (ha-leader "s" '(:ignore t :which-key "search") "s q" '("close" . ha-rg-close-results-buffer) @@ -891,6 +878,12 @@ Install the [[https://github.com/dajva/rg.el][rg]] package, which builds on the (compile-goto-error))) #+end_src Note we bind the key ~M-R~ to the [[help:rg-menu][rg-menu]], which is a Magit-like interface to =ripgrep=. + +I don’t understand the bug associated with the =:general= extension to =use-package=, but it /works/, but stops everything else from working, so pulling it out into its own =use-package= section addresses that issue: +#+begin_src emacs-lisp + (use-package rg + :general (:states 'normal "gr" 'rg-dwim)) +#+end_src **** wgrep The [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep package]] integrates with =ripgrep=. Typically, you hit ~i~ to automatically go into =wgrep-mode= and edit away, but since I typically want to edit everything at the same time, I have a toggle that should work as well: #+begin_src emacs-lisp @@ -900,7 +893,7 @@ The [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep package]] integrates wi :hook (rg-mode-hook . wgrep-rg-setup) :config (ha-leader - :keymaps 'rg-mode-map ; Actually, `i` works! + :keymaps 'rg-mode-map ; Actually, `i' works! "s w" '("wgrep-mode" . wgrep-change-to-wgrep-mode) "t w" '("wgrep-mode" . wgrep-change-to-wgrep-mode))) #+end_src diff --git a/ha-org.org b/ha-org.org index 374cd48..e35ec73 100644 --- a/ha-org.org +++ b/ha-org.org @@ -138,7 +138,7 @@ I should break this function into smaller bits ... #+begin_src emacs-lisp (defun ha-org-special-return (&optional ignore) - "Add new list item, heading or table row with RET. + "Add new list item with RET. A double return on an empty element deletes it. Use a prefix arg to get regular RET." (interactive "P") @@ -156,30 +156,11 @@ I should break this function into smaller bits ... (org-insert-item)) (delete-region (line-beginning-position) (line-end-position)))) - ;; ((org-at-heading-p) - ;; (if (string= "" (org-element-property :title (org-element-context))) - ;; (delete-region (line-beginning-position) (line-end-position)) - ;; (org-insert-heading-after-current))) - - ((org-at-table-p) - (if (-any? - (lambda (x) (not (string= "" x))) - (nth - (- (org-table-current-dline) 1) - (org-table-to-lisp))) - (org-return) - ;; empty row - (beginning-of-line) - (setf (buffer-substring - (line-beginning-position) (line-end-position)) "") - (org-return))) - (t (org-return))))) #+end_src How do we know if we are in a list item? Lists end with two blank lines, so we need to make sure we are also not at the beginning of a line to avoid a loop where a new entry gets created with one blank line. - #+begin_src emacs-lisp (defun org-really-in-item-p () "Return item beginning position when in a plain list, nil otherwise. @@ -373,17 +354,14 @@ And turn on ALL the languages: (plantuml . t))) #+end_src *** REST Web Services -:PROPERTIES: -:header-args: :var user-agent="my-super-agent" -:END: -There are many ways in Emacs to query to investigate REST-oriented web services. The [[https://github.com/zweifisch/ob-http][ob-http]] adds HTTP calls to standard org blocks. +Emacs has two ways to query and investigate REST-oriented web services. The [[https://github.com/zweifisch/ob-http][ob-http]] adds HTTP calls to standard org blocks. #+begin_src emacs-lisp (use-package ob-http :init (add-to-list 'org-babel-load-languages '(http . t))) #+end_src And let’s see how it works: -#+begin_src http :pretty :results value replace :wrap src js +#+begin_src http :pretty :results value replace :wrap src js :var user-agent="my-super-agent" GET https://api.github.com/repos/zweifisch/ob-http/languages Accept: application/json User-Agent: ${user-agent} @@ -405,7 +383,7 @@ Another approach is [[https://github.com/alf/ob-restclient.el][ob-restclient]], #+end_src And let’s try this: -#+begin_src restclient :results value replace :wrap src js +#+begin_src restclient :results value replace :wrap src js :var user-agent="my-super-agent" GET https://api.github.com/repos/zweifisch/ob-http/languages Accept: application/vnd.github.moondragon+json User-Agent: ${user-agent}