move my to own directory and add a config update check button to dashboard

This commit is contained in:
2021-01-29 22:43:32 +01:00
parent 3f52b164d2
commit 84eb4929ee
6 changed files with 55 additions and 533 deletions

View File

@@ -19,11 +19,17 @@
;; Over an element, like a table. The key must start with attr_.
;; The lower line shows the plist elements inside the org element context.
(require 'my-view)
(defgroup my nil
"My concept mapping"
:prefix "my-"
:group 'emacs)
(defun my-eval-string (string)
"Evaluate elisp code stored in a string."
(eval (car (read-from-string (format "(progn %s)" string)))))
(defun my-list-delete (element list)
"Destructive version of `delete'.
LIST will be nil if the last ELEMENT was deleted.
@@ -36,6 +42,21 @@ Example:
(my-list-delete '(\"a\") 'my-list)"
(set list (delete element (symbol-value list))))
(defun my-list-to-org-table (lst)
"Convert list into an Org table."
(let ((lines lst)
(rows)
(tbl))
(while lines
(setq rows (car lines))
(setq tbl (concat tbl "|"))
(while rows
(setq tbl (concat tbl (format "%s|" (car rows))))
(setq rows (cdr rows)))
(setq tbl (concat tbl "\n"))
(setq lines (cdr lines)))
tbl))
(defmacro my-plist-put (plist &rest args)
"Example usage:
(my-plist-put my-org-table-colored-cells 'table-name '(\"@23$3\" \"blue\"))
@@ -397,114 +418,31 @@ Usage:
) ;; with-eval-after-load 'org
(defun my-view-python ()
"Three windows.
On the right side a *Anaconda* buffer with optionally
`virtual-auto-fill-mode' active and a *Python* buffer."
(interactive)
(require 'python)
(unless (get-buffer (concat "*" python-shell-buffer-name "*"))
(run-python) ;; cursor is now inside the python buffer.
(other-window -1)
)
(delete-other-windows)
(split-window-horizontally (truncate (* 0.6 (window-body-width))))
(other-window 1)
(switch-to-buffer (concat "*" python-shell-buffer-name "*"))
(split-window-vertically) ;; both are python buffers now.
(switch-to-buffer "*Anaconda*")
(when (fboundp 'virtual-auto-fill-mode) (virtual-auto-fill-mode))
(other-window -1)
)
(defun my-view-elisp ()
"Two windows side-by-side.
On the right side a *Help* buffer with optionally
`virtual-auto-fill-mode' active."
(interactive)
(delete-other-windows)
(split-window-horizontally (truncate (* 0.6 (window-body-width))))
(other-window 1)
(switch-to-buffer "*Help*")
(other-window -1)
)
(defun my-view-shell ()
"Two windows side-by-side.
On the right side a *compilation* buffer.
Use `compile' with `sh <foo.sh -flag command>' to run the script."
;; TODO: rebind compile to C-c and auto fill sh with filename
;; TODO: rebind recompile to ??? to use last compile command
;; https://masteringemacs.org/article/compiling-running-scripts-emacs
;; TODO: for shell-script buffers:
;; ;;; Shut up compile saves
;; (setq compilation-ask-about-save nil)
;; ;;; Don't save *anything*
;; (setq compilation-save-buffers-predicate '(lambda () nil))
(interactive)
(delete-other-windows)
(split-window-horizontally (truncate (* 0.6 (window-body-width))))
(other-window 1)
(switch-to-buffer "*compilation*")
(other-window -1)
)
(defun my-view-org-pdf ()
"Two windows side-by-side.
On the right side a DocView buffer displaying the pdf."
(interactive)
(delete-other-windows)
(let ((bufnam (buffer-name))
(buffilnam buffer-file-name))
(split-window-horizontally)
(other-window 1)
;;(switch-to-buffer (concat (file-name-sans-extension bufnam) ".pdf"))
(find-file (concat (file-name-sans-extension buffilnam) ".pdf"))
(doc-view-fit-height-to-window)
(doc-view-fit-window-to-page)
(other-window -1)
))
(defun my-view-gnuplot ()
"Three windows.
On the right side a *Shell* buffer with optionally
`virtual-auto-fill-mode' active and an Image mode buffer."
(interactive)
(save-excursion
(let (output-file-name) ;; get figure output name
(goto-char (point-min))
(when (re-search-forward "set output .*" nil t)
;; TODO: search text in between set output '...' then I do not
;; need to replace / remove part of the match string.
(setq output-file-name (match-string 0))
(setq output-file-name (string-replace "set output " "" output-file-name))
(setq output-file-name (substring output-file-name 1 -1)))
;;(message "%s" output-file-name)
(delete-other-windows)
(split-window-horizontally (truncate (* 0.6 (window-body-width))))
(other-window 1)
(if output-file-name
;;(switch-to-buffer output-file-name)
(find-file output-file-name)
;;(switch-to-buffer "*scratch*")
(switch-to-buffer " *image*"))
;;(when (fboundp 'virtual-auto-fill-mode) (virtual-auto-fill-mode))
(split-window-vertically) ;; both are shell buffers now.
(switch-to-buffer "*shell*")
(shell)
;;(when (fboundp 'virtual-auto-fill-mode) (virtual-auto-fill-mode))
(other-window -1))))
(defun my-magit-repo-status (directory branch &optional with-update as-text)
(when (fboundp 'magit)
(let* ((default-directory directory)
(remotes (magit-list-remotes))
(diff))
(when (= (length remotes) 1)
(let* ((remote-branch-name (concat (car remotes) "/" branch)) ;; @{u} may not configured, TODO: (if (magit-rev-parse "@{u}") ...)
(diff-count (magit-rev-diff-count "@" remote-branch-name))) ;; i.e. git rev-list @...origin/master --count --left-right
(when with-update (magit-git-fetch (concat (car remotes) " " branch)))
(setq diff (- (car diff-count) (cadr diff-count)))))
(if as-text
(if (= diff 0) "Up-to-date"
(if (> diff 0) "Need to pull"
"Need to push"))
diff))))
(defun my-dashboard-config-update ()
(if (fboundp 'magit)
(let ((diff (my-magit-repo-status "~/.config/emacs" "master")))
(if (= diff 0) "Up-to-date"
(if (= diff 1) "1 update"
(if (> diff 0) (format "%s updates" diff)
(if (= diff -1) "1 commit unpushed"
(format "%s commits unpushed" (- diff)))))))
(require 'magit nil t)
"Check"))
(provide 'my)
;;; my.el ends here