From f337048da36c3131752293b1afceb479724351d9 Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Mon, 8 Nov 2021 16:02:39 -0800 Subject: [PATCH] Fixed bugs and made things more consistent, ha- Making the Git menu more consistent as well. --- ha-config.org | 13 +++++++------ ha-org-clipboard.org | 36 ++++++++++++++++++------------------ ha-org.org | 8 +++++--- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/ha-config.org b/ha-config.org index e804de2..35a0e71 100644 --- a/ha-config.org +++ b/ha-config.org @@ -705,9 +705,10 @@ To do this, we need a way to generate a string of the perspectives in alphabetic number and NAMES is a list of strings." (when names (concat - (format " %d: %s" ; Shame that the following doesn't work: + (format " %d: %s%s" ; Shame that the following doesn't work: num ; (propertize (number-to-string num) :foreground "#00a0") - (car names)) ; Nor does surrounding the number with underbars. + (car names) ; Nor does surrounding the number with underbars. + (if (equal (car names) (projectile-project-name)) "*" "")) (ha--persp-label (1+ num) (cdr names))))) (defun ha-persp-labels () @@ -730,9 +731,9 @@ Build the hydra as well as configure the =perspective= project. Workspaces- %s(ha-persp-labels) _n_: new project _r_: rename _a_: add buffer _l_: load worksp _]_: next worksp _d_: delete _b_: goto buffer _s_: save worksp - _[_: previous _W_: init all _k_: remove buffer - " + _[_: previous _W_: init all _k_: remove buffer _`_: to last worksp " ("TAB" persp-switch) + ("`" persp-switch-last) ("1" (persp-switch-by-number 1)) ("2" (persp-switch-by-number 2)) ("3" (persp-switch-by-number 3)) @@ -889,8 +890,8 @@ Can not live without [[https://magit.vc/][Magit]], a Git porcelain for Emacs. I "g o" '(:ignore t :which-key "open") "g c" '(:ignore t :which-key "create") - "g c r" '("Initialize repo" . magit-init) - "g c R" '("Clone repo" . magit-clone) + "g c R" '("Initialize repo" . magit-init) + "g c C" '("Clone repo" . magit-clone) "g c c" '("Commit" . magit-commit-create) "g c f" '("Fixup" . magit-commit-fixup) "g c b" '("Branch" . magit-branch-and-checkout))) diff --git a/ha-org-clipboard.org b/ha-org-clipboard.org index 80814b6..9c89709 100644 --- a/ha-org-clipboard.org +++ b/ha-org-clipboard.org @@ -33,27 +33,27 @@ Functions to help convert content from the operating system's clipboard into org Each operating system as a different way of working with the clipboard, so let's create an operating-system abstraction: #+BEGIN_SRC emacs-lisp -(defun ha/get-clipboard () +(defun ha-get-clipboard () "Returns a list where the first entry is the content type, either :html or :text, and the second is the clipboard contents." (if (eq system-type 'darwin) - (ha/get-mac-clipboard) - (ha/get-linux-clipboard))) + (ha-get-mac-clipboard) + (ha-get-linux-clipboard))) #+END_SRC Let's define the clipboard for a Mac. The challenge here is that we need to binary unpack the data from a call to Applescript. #+BEGIN_SRC emacs-lisp -(defun ha/get-mac-clipboard () +(defun ha-get-mac-clipboard () "Returns a list where the first entry is the content type, either :html or :text, and the second is the clipboard contents." (destructuring-bind (exit-code contents) (shell-command-with-exit-code "osascript" "-e" "the clipboard as \"HTML\"") (if (= 0 exit-code) - (list :html (ha/convert-applescript-to-html contents)) + (list :html (ha-convert-applescript-to-html contents)) (list :text (shell-command-to-string "osascript -e 'the clipboard'"))))) -(defun ha/convert-applescript-to-html (packed-contents) +(defun ha-convert-applescript-to-html (packed-contents) "Applescript's clipboard returns the contents in a packed array. Convert and return this encoding into a UTF-8 string." (cl-flet ((hex-pack-bytes (tuple) (string-to-number (apply 'string tuple) 16))) @@ -70,8 +70,8 @@ Convert and return this encoding into a UTF-8 string." And define the same interface for Linux. Keep in mind, we need the exit code from calling a process, so I am going to define/use a helper function (that really should go into the piper project). #+BEGIN_SRC emacs-lisp -(defun ha/get-linux-clipboard () - "Return the clipbaard for a Unix-based system. See `ha/get-clipboard'." +(defun ha-get-linux-clipboard () + "Return the clipbaard for a Unix-based system. See `ha-get-clipboard'." (destructuring-bind (exit-code contents) (shell-command-with-exit-code "xclip" "-o" "-t" "text/html") (if (= 0 exit-code) @@ -90,7 +90,7 @@ And define the same interface for Linux. Keep in mind, we need the exit code fro We can assume that most non-HTML text could be Slack-like: #+BEGIN_SRC emacs-lisp -(defun ha/slack-to-markdown-buffer () +(defun ha-slack-to-markdown-buffer () "Odd function that converts Slack’s version of Markdown (where code is delimited with triple backticks) into a more formal four-space indent markdown style." @@ -123,29 +123,29 @@ four-space indent markdown style." Let's work top-down at this point with the interactive function that inserts the clipboard into the current buffer: #+BEGIN_SRC emacs-lisp -(defun ha/org-yank-clipboard () +(defun ha-org-yank-clipboard () "Yanks (pastes) the contents of the Apple Mac clipboard in an org-mode-compatible format." (interactive) - (insert (ha/org-clipboard))) + (insert (ha-org-clipboard))) #+END_SRC The heavy lifting, however is done by this function. Note that I will need another function to tidy up the output from =pandoc= that will be more to my liking. #+BEGIN_SRC emacs-lisp -(defun ha/org-clipboard () +(defun ha-org-clipboard () "Return the contents of the clipboard in org-mode format." - (seq-let (type contents) (ha/get-clipboard) + (seq-let (type contents) (ha-get-clipboard) (with-temp-buffer (insert contents) (if (eq :html type) (shell-command-on-region (point-min) (point-max) "pandoc -f html -t org" t t) - (ha/slack-to-markdown-buffer) + (ha-slack-to-markdown-buffer) (shell-command-on-region (point-min) (point-max) "pandoc -f markdown -t org" t t)) - (ha/html-paste-touchup) + (ha-html-paste-touchup) (buffer-substring-no-properties (point-min) (point-max))))) -(defun ha/html-paste-touchup () +(defun ha-html-paste-touchup () "Attempts to fix the org produced by `pandoc'' that seems to plague us." (interactive) (dolist (combo '((" (edited) " " ") ; Slack appends this phrase that is never needed @@ -164,11 +164,11 @@ The heavy lifting, however is done by this function. Note that I will need anoth #+END_SRC * Keybinding to Paste into Org Files -We +We just need to bind it to the /local/ mode key sequence: #+BEGIN_SRC emacs-lisp (general-evil-define-key 'normal org-mode-map :prefix "SPC m" - "y" 'ha/org-yank-clipboard) + "y" 'ha-org-yank-clipboard) #+END_SRC * Technical Artifacts :noexport: diff --git a/ha-org.org b/ha-org.org index db96290..d9f125b 100644 --- a/ha-org.org +++ b/ha-org.org @@ -290,10 +290,12 @@ To make the snippets more context aware, this predicate (plist-get (cadr (org-element-at-point)) :language))) #+END_SRC ** Keybindings -Ugh +Keybindings specific to org files: #+BEGIN_SRC emacs-lisp :tangle no -(ha-leader :keymaps 'org-mode-map - "m l" 'org-insert-link) + (general-evil-define-key 'normal org-mode-map + :prefix "SPC m" + "e" 'org-export-dispatch + "y" 'org-insert-link) #+END_SRC * Supporting Packages At this point, we assume that the =use-package= for org is complete, so we can close it and allow other projects to be loaded: