fix(emacs): my fork of wakatime, webmode+vue, EMMS

This commit is contained in:
Pavel Korytov 2021-08-31 16:39:15 +05:00
parent 4d759a129c
commit 3576f37d27
2 changed files with 31 additions and 104 deletions

View file

@ -669,50 +669,10 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
(general-imap "M-TAB" 'company-yasnippet)
(use-package wakatime-mode
:straight t
:straight (:host github :repo "SqrtMinusOne/wakatime-mode")
:if (not my/is-termux)
:config
(defun wakatime-client-command (savep)
"Return client command executable and arguments.
Set SAVEP to non-nil for write action."
(format "%s%s--entity \"%s\" --plugin \"%s/%s\" --time %.2f%s%s"
(if (s-blank wakatime-python-bin) "" (format "\"%s\" " wakatime-python-bin))
(if (s-blank wakatime-cli-path) "wakatime " (format "\"%s\" " wakatime-cli-path))
(buffer-file-name (current-buffer))
wakatime-user-agent
wakatime-version
(float-time)
(if savep " --write" "")
(if (s-blank wakatime-api-key) "" (format " --key %s" wakatime-api-key))))
(defun wakatime-call (savep)
"Call WakaTime command."
(let*
((command (wakatime-client-command savep))
(process-environment (if wakatime-python-path (cons (format "PYTHONPATH=%s" wakatime-python-path) process-environment) process-environment))
(process
(start-process
"Shell"
(generate-new-buffer " *WakaTime messages*")
shell-file-name
shell-command-switch
command)))
(set-process-sentinel process
`(lambda (process signal)
(when (memq (process-status process) '(exit signal))
(kill-buffer (process-buffer process))
(let ((exit-status (process-exit-status process)))
(when (and (not (= 0 exit-status)) (not (= 102 exit-status)) (not (= 1 exit-status)))
(when wakatime-disable-on-error
(wakatime-mode -1)
(global-wakatime-mode -1))
(cond
((= exit-status 103) (error "WakaTime Error (%s) Config file parse error. Check your ~/.wakatime.cfg file." exit-status))
((= exit-status 104) (error "WakaTime Error (%s) Invalid API Key. Set your api key with: (custom-set-variables '(wakatime-api-key \"XXXX\"))" exit-status))
((= exit-status 105) (error "WakaTime Error (%s) Unknown wakatime-cli error. Please check your ~/.wakatime.log file and open a new issue at https://github.com/wakatime/wakatime-mode" exit-status))
((= exit-status 106) (error "WakaTime Error (%s) Malformed heartbeat error. Please check your ~/.wakatime.log file and open a new issue at https://github.com/wakatime/wakatime-mode" exit-status))
(t (message "WakaTime Error (%s) Make sure this command runs in a Terminal: %s" exit-status (wakatime-client-command nil)))))))))
(set-process-query-on-exit-flag process nil)))
(setq wakatime-ignore-exit-codes '(0 1 102))
(advice-add 'wakatime-init :after (lambda () (setq wakatime-cli-path "/home/pavel/bin/wakatime-cli")))
;; (setq wakatime-cli-path (executable-find "wakatime"))
(global-wakatime-mode))
@ -2083,7 +2043,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
:straight t
:init
(my-leader-def
:keymaps '(js-mode-map typescript-mode-map vue-mode-map svelte-mode-map)
:keymaps '(js-mode-map web-mode-map typescript-mode-map vue-mode-map svelte-mode-map)
"rr" #'prettier-prettify))
(use-package typescript-mode
@ -2130,7 +2090,8 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
:config
(add-hook 'web-mode-hook 'smartparens-mode)
(add-hook 'web-mode-hook 'hs-minor-mode)
(my/set-smartparens-indent 'web-mode))
(my/set-smartparens-indent 'web-mode)
(add-hook 'web-mode-hook ))
(setq my/web-mode-lsp-extensions
`(,(rx ".svelte" eos)
@ -2144,6 +2105,12 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
(add-hook 'web-mode-hook #'my/web-mode-lsp)
(defun my/web-mode-vue-setup ()
(when (string-match-p (rx ".vue" eos) (buffer-name))
(setq-local web-mode-script-padding 0)))
(add-hook 'web-mode-hook 'my/web-mode-vue-setup)
(use-package vue-mode
:straight t
:disabled
@ -2714,7 +2681,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
(if asc
(cdr asc)
(let ((python-executable
(string-trim (shell-command-to-string "PIPENV_IGNORE_VIRTUALENVS=1 pipenv run which python"))))
(string-trim (shell-command-to-string "PIPENV_IGNORE_VIRTUALENVS=1 pipenv run which python 2>/dev/null"))))
(if (string-match-p ".*not found.*" python-executable)
(message "Pipfile found, but not pipenv executable!")
(message (format "Found pipenv python: %s" python-executable))
@ -3086,7 +3053,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
(emms-player-simple-regexp
"m3u" "ogg" "flac" "mp3" "wav" "mod" "au" "aiff"))
;; MPV setup
(add-to-list 'emms-player-list 'emms-player-mpv t)
(add-to-list 'emms-player-list 'emms-player-mpv)
(emms-player-set emms-player-mpv
'regex
(rx (or (: "https://" (* nonl) "youtube.com" (* nonl))
@ -3173,7 +3140,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
(my-leader-def "asc" #'my/emms-cleanup-urls)
(use-package lyrics-fetcher
:straight (:host github :repo "SqrtMinusOne/lyrics-fetcher.el")
:straight t
:after (emms)
:init
(my-leader-def

View file

@ -1318,65 +1318,15 @@ Before I figure out how to package this for Guix:
#+begin_src emacs-lisp :noweb yes
(use-package wakatime-mode
:straight t
:straight (:host github :repo "SqrtMinusOne/wakatime-mode")
:if (not my/is-termux)
:config
<<wakatime-fixes>>
(setq wakatime-ignore-exit-codes '(0 1 102))
(advice-add 'wakatime-init :after (lambda () (setq wakatime-cli-path "/home/pavel/bin/wakatime-cli")))
;; (setq wakatime-cli-path (executable-find "wakatime"))
(global-wakatime-mode))
#+end_src
**** Fixes
wakatime-mode.el seems to be incompatible with the latest Go cli. The fix is to replace =--file= with =--entity=.
#+begin_src emacs-lisp :tangle no :noweb-ref wakatime-fixes
(defun wakatime-client-command (savep)
"Return client command executable and arguments.
Set SAVEP to non-nil for write action."
(format "%s%s--entity \"%s\" --plugin \"%s/%s\" --time %.2f%s%s"
(if (s-blank wakatime-python-bin) "" (format "\"%s\" " wakatime-python-bin))
(if (s-blank wakatime-cli-path) "wakatime " (format "\"%s\" " wakatime-cli-path))
(buffer-file-name (current-buffer))
wakatime-user-agent
wakatime-version
(float-time)
(if savep " --write" "")
(if (s-blank wakatime-api-key) "" (format " --key %s" wakatime-api-key))))
#+end_src
Also, until [[https://github.com/wakatime/wakatime-cli/issues/509][this issue]] is resolved, I set =wakatime-call= to ignore exit-code 1.
#+begin_src emacs-lisp :tangle no :noweb-ref wakatime-fixes
(defun wakatime-call (savep)
"Call WakaTime command."
(let*
((command (wakatime-client-command savep))
(process-environment (if wakatime-python-path (cons (format "PYTHONPATH=%s" wakatime-python-path) process-environment) process-environment))
(process
(start-process
"Shell"
(generate-new-buffer " *WakaTime messages*")
shell-file-name
shell-command-switch
command)))
(set-process-sentinel process
`(lambda (process signal)
(when (memq (process-status process) '(exit signal))
(kill-buffer (process-buffer process))
(let ((exit-status (process-exit-status process)))
(when (and (not (= 0 exit-status)) (not (= 102 exit-status)) (not (= 1 exit-status)))
(when wakatime-disable-on-error
(wakatime-mode -1)
(global-wakatime-mode -1))
(cond
((= exit-status 103) (error "WakaTime Error (%s) Config file parse error. Check your ~/.wakatime.cfg file." exit-status))
((= exit-status 104) (error "WakaTime Error (%s) Invalid API Key. Set your api key with: (custom-set-variables '(wakatime-api-key \"XXXX\"))" exit-status))
((= exit-status 105) (error "WakaTime Error (%s) Unknown wakatime-cli error. Please check your ~/.wakatime.log file and open a new issue at https://github.com/wakatime/wakatime-mode" exit-status))
((= exit-status 106) (error "WakaTime Error (%s) Malformed heartbeat error. Please check your ~/.wakatime.log file and open a new issue at https://github.com/wakatime/wakatime-mode" exit-status))
(t (message "WakaTime Error (%s) Make sure this command runs in a Terminal: %s" exit-status (wakatime-client-command nil)))))))))
(set-process-query-on-exit-flag process nil)))
#+end_src
*** ActivityWatch
#+begin_src emacs-lisp
(use-package request
@ -3472,7 +3422,7 @@ My bit of config here:
:straight t
:init
(my-leader-def
:keymaps '(js-mode-map typescript-mode-map vue-mode-map svelte-mode-map)
:keymaps '(js-mode-map web-mode-map typescript-mode-map vue-mode-map svelte-mode-map)
"rr" #'prettier-prettify))
#+end_src
*** TypeScript
@ -3534,7 +3484,8 @@ Trying this one out instead of vue-mode and svelte-mode, because this one seems
:config
(add-hook 'web-mode-hook 'smartparens-mode)
(add-hook 'web-mode-hook 'hs-minor-mode)
(my/set-smartparens-indent 'web-mode))
(my/set-smartparens-indent 'web-mode)
(add-hook 'web-mode-hook ))
#+end_src
Hooking this up with lsp.
@ -3551,6 +3502,15 @@ Hooking this up with lsp.
(add-hook 'web-mode-hook #'my/web-mode-lsp)
#+end_src
Vue settings
#+begin_src emacs-lisp
(defun my/web-mode-vue-setup ()
(when (string-match-p (rx ".vue" eos) (buffer-name))
(setq-local web-mode-script-padding 0)))
(add-hook 'web-mode-hook 'my/web-mode-vue-setup)
#+end_src
*** OFF (OFF) Vue.js
#+begin_src emacs-lisp :noweb yes
(use-package vue-mode
@ -4097,7 +4057,7 @@ For some reason it doesn't use pipenv python executable, so here is a small work
(if asc
(cdr asc)
(let ((python-executable
(string-trim (shell-command-to-string "PIPENV_IGNORE_VIRTUALENVS=1 pipenv run which python"))))
(string-trim (shell-command-to-string "PIPENV_IGNORE_VIRTUALENVS=1 pipenv run which python 2>/dev/null"))))
(if (string-match-p ".*not found.*" python-executable)
(message "Pipfile found, but not pipenv executable!")
(message (format "Found pipenv python: %s" python-executable))
@ -4680,7 +4640,7 @@ After all this is done, run =M-x emms-cache-set-from-mpd-all= to set cache from
[[https://mpv.io/][mpv]] is a decent media player, which has found a place in this configuration because it integrates with youtube-dl.
#+begin_src emacs-lisp
(add-to-list 'emms-player-list 'emms-player-mpv t)
(add-to-list 'emms-player-list 'emms-player-mpv)
#+end_src
Also a custom regex. My demands for MPV include running =youtube-dl=, so there is a regex that matches youtube.com or some of the video formats.
@ -4737,7 +4697,7 @@ My package for fetching EMMS lyrics and album covers.
#+begin_src emacs-lisp
(use-package lyrics-fetcher
:straight (:host github :repo "SqrtMinusOne/lyrics-fetcher.el")
:straight t
:after (emms)
:init
(my-leader-def