]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Extract some-button to an external lisp file
authorEshel Yaron <eshel@areionsec.com>
Wed, 18 May 2022 12:47:12 +0000 (15:47 +0300)
committerEshel Yaron <eshel@areionsec.com>
Wed, 18 May 2022 12:47:12 +0000 (15:47 +0300)
.emacs.d/esy.org

index fb745b4dd104991462dc2023d609daa5af318caf..be26cb6218e3014b869ccfe876e967f6d940214b 100644 (file)
@@ -87,7 +87,8 @@ For further information about Elisp headers, see [[info:elisp#Library
   ;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
 
   ;;; Package-Requires: ((emacs "29"))
-  ;;; Commentary: Tangled version of esy.org
+  ;;; Commentary:
+  ;;  Tangled version of esy.org
   ;;; Code:
 #+end_src
 
@@ -145,6 +146,12 @@ For further information about Elisp headers, see [[info:elisp#Library
   (package-install-selected-packages)
 #+end_src
 
+* Add local Elisp directory to load-path
+
+#+begin_src emacs-lisp
+  (add-to-list 'load-path (expand-file-name  "lisp/" user-emacs-directory))
+#+end_src
+
 * Suppressing native compilation warnings
 :PROPERTIES:
 :CUSTOM_ID: native-compilation
@@ -191,7 +198,7 @@ For further information about Elisp headers, see [[info:elisp#Library
     (save-place-mode 1)
     (setq bookmark-save-flag 1))
 
-  (esy/setup-history)
+  (add-hook 'after-init-hook #'esy/setup-history)
 #+end_src
 
 ** Persist Git log messages history across Emacs sessions
@@ -231,6 +238,7 @@ For a list of available frame parameters, see [[info:elisp#Frame Parameters][eli
 #+begin_src emacs-lisp
   (setq use-file-dialog nil
         use-dialog-box nil
+        initial-scratch-message "; Go.\n"
         ns-use-native-fullscreen t
         inhibit-startup-screen t
         ring-bell-function 'ignore)
@@ -749,15 +757,14 @@ refiling directly into deeper headings as well.
 :CUSTOM_ID: global-keybindings
 :END:
 
-** Misc. keybindings
+** Custom kill command                                                 :cmd:
 :PROPERTIES:
-:CUSTOM_ID: misc-keybindings
+:CUSTOM_ID: kill-dwim-command
 :END:
 
 #+begin_src emacs-lisp
   (defun esy/kill-dwim ()
-    "When region is active, kill region, otherwise kill last word.
-  Arguments BEG and END are the borders of the region."
+    "When region is active, kill region, otherwise kill last word."
     (interactive)
     (if (region-active-p)
         (let ((beg (region-beginning))
@@ -766,7 +773,14 @@ refiling directly into deeper headings as well.
       (let ((end (point)))
         (backward-word)
         (kill-region (point) end))))
+#+end_src
 
+** Misc. keybindings
+:PROPERTIES:
+:CUSTOM_ID: misc-keybindings
+:END:
+
+#+begin_src emacs-lisp
   (defun esy/customize-global-keymap ()
     "Configure the global keymap."
     (require 'consult)
@@ -833,12 +847,11 @@ refiling directly into deeper headings as well.
 #+begin_src emacs-lisp
   (defun esy/customize-search-map ()
     "Configure the `search-map' keymap."
-    (keymap-set search-map "b" #'esy/push-button))
+    (keymap-set search-map "b" #'some-button))
 
   (add-hook 'after-init-hook #'esy/customize-search-map)
 #+end_src
 
-
 ** =ace-window= homerow keys
 :PROPERTIES:
 :CUSTOM_ID: ace-window
@@ -1171,16 +1184,6 @@ does in the shell.
   (add-hook 'after-init-hook #'display-battery-mode)
 #+end_src
 
-* Setup PATH from shell environment
-:PROPERTIES:
-:CUSTOM_ID: path-from-shell
-:END:
-
-#+begin_src emacs-lisp
-  (require 'exec-path-from-shell)
-  (add-hook 'after-init-hook #'exec-path-from-shell-initialize)
-#+end_src
-
 * Programming
 :PROPERTIES:
 :CUSTOM_ID: programming
@@ -1299,125 +1302,6 @@ Add the timezones of places of interest to the list of clocks shown by
     (add-to-list 'zoneinfo-style-world-list '("Europe/Amsterdam" "Amsterdam")))
 #+end_src
 
-** Push a button in the current buffer with completions                :cmd:
-  :PROPERTIES:
-  :CUSTOM_ID: completing-push-button
-  :CreatedAt: <2022-05-14 Sat>
-  :CapturedAt: 
-  :CapturedAs: Emacs configuration fragment
-  :END:
-
-#+begin_src emacs-lisp
-  (defvar esy/preview-table nil)
-  (defvar esy/preview-window nil)
-  (defvar esy/preview-buffer nil)
-
-  (defun esy/preview-completion (&rest _)
-    "Preview the current completion."
-    (let* ((completion (with-minibuffer-completions-window
-                         (substring-no-properties
-                          (get-text-property (point)
-                                             'completion--string))))
-           (pos (cdr (assoc completion esy/preview-table))))
-      (with-selected-window esy/preview-window
-        (unless (= (goto-char pos) (point))
-          (widen)
-          (goto-char pos))
-        (recenter)
-        (pulse-momentary-highlight-one-line))))
-
-  (defun esy/button-completion-candidate (index button)
-    "Return a completion candidate for BUTTON prefixed by INDEX."
-    (cons (concat (propertize (format "%d " index)
-                              'invisible t)
-                  (truncate-string-to-width
-                   (esy/inline (button-label button))
-                   64 nil ?\s t))
-          (button-start button)))
-
-  (defun esy/buttons (&optional buffer pom)
-    "Return an alist of buttons in BUFFER.
-  Buttons following POM appear first in the resulting list."
-    (with-current-buffer (or buffer (current-buffer))
-      (let ((pos (or pom (point)))
-            (button (next-button (point-min)))
-            (index 1)
-            (buttons-before nil)
-            (buttons-after nil))
-        (while (and button (< (button-start button) pos))
-          (setq buttons-before
-                (cons (esy/button-completion-candidate index button)
-                      buttons-before))
-          (setq index (1+ index))
-          (setq button (next-button (button-end button))))
-        (while button
-          (setq buttons-after
-                (cons (esy/button-completion-candidate index button)
-                      buttons-after))
-          (setq index (1+ index))
-          (setq button (next-button (button-end button))))
-        (append (reverse buttons-after) (reverse buttons-before)))))
-
-  (defun esy/inline (str)
-    "Inline STR."
-    (when str
-      (string-replace "\n" " " str)))
-
-  (defun esy/completing-read-with-preview (prompt collection window buffer)
-    "Prompt for an element of COLLECTION with preview of the selection.
-  PROMPT passed on to `completing-read'.  WINDOW is the window in
-  which to show preview for locations in BUFFER."
-    (advice-add #'next-completion :after #'esy/preview-completion)
-    (unwind-protect
-        (let ((esy/preview-window window)
-              (esy/preview-buffer buffer)
-              (esy/preview-table collection)
-              (completions-sort nil)
-              ;  completion-extra-properties seems to get clobbered?
-              ;; (completion-extra-properties '(:annotate-function
-              ;;                                esy/annotate-button))
-              (completion-annotate-function #'esy/annotate-button))
-          (completing-read prompt collection nil t nil nil (caar collection)))
-      (advice-remove #'next-completion #'esy/preview-completion)))
-
-  (defun esy/annotate-button (key)
-    "Annotate completion candidate KEY with its button properties."
-    (with-current-buffer esy/preview-buffer
-      (let* ((button (button-at
-                      (cdr
-                       (assoc key esy/preview-table))))
-             (type (or (button-type button)
-                       (button-get button 'action)))
-             (url (button-get button 'shr-url)))
-        (esy/inline
-         (if type
-             (if url
-                 (format "%S %s" type url)
-               (format "%S" type))
-           (when url
-             (format "%s" url)))))))
-
-  (defun esy/push-button ()
-    "Push a button in the current buffer with comlpetions and preview."
-    (interactive)
-    (if-let ((buf (current-buffer))
-             (win (selected-window))
-             (table (esy/buttons)))
-        (let* ((choice (save-excursion
-                         (esy/completing-read-with-preview "Button: "
-                                                           table
-                                                           win
-                                                           buf)))
-               (pos (cdr (assoc choice table))))
-          (or (ignore-errors
-                (push-button pos))
-              (progn
-                (goto-char pos)
-                (shr-browse-url))))
-      (user-error "No buttons in current buffer")))
-
-#+end_src
-
 * Elisp Footer
 :PROPERTIES:
 :CUSTOM_ID: footer