From b855e3a6af616b8b366c1cad509df9f3d87aa565 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Thu, 22 Feb 2024 11:58:54 +0800 Subject: view: minor refactoring --- view-conf.el | 196 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 130 insertions(+), 66 deletions(-) diff --git a/view-conf.el b/view-conf.el index d2f0838..3a7a9f5 100644 --- a/view-conf.el +++ b/view-conf.el @@ -1,4 +1,30 @@ -;;; view-conf.el --- My configurations to view things -*- lexical-binding: t; -*- +;;; view-conf.el --- For viewing -*- lexical-binding: t; -*- + +;; Copyright (C) 2024 Durand + +;; Author: Durand +;; Keywords: convenience, hardware + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation, either version 3 of the +;; License, or (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see +;; . + +;;; Commentary: + +;; My configurations for more conveniently viewing buffers and some +;; systems information. + +;;; Code: ;;; View tmeperatures or timers ;;;###autoload @@ -24,56 +50,85 @@ If ARG is '(16), view the battery information." battery-temp) (with-temp-buffer ;; NOTE: First fans information - (insert (funcall - (plist-get (car (auth-source-search :host "local-computer")) - :secret))) + (insert + (funcall + (plist-get + (car (auth-source-search :host "local-computer")) + :secret))) (call-process-region nil nil "sudo" nil t nil "-S" "powermetrics" "-i1" "-n1" "-ssmc") (goto-char (point-min)) (search-forward "Fan" nil t) - (setf fan-speed - (progn (re-search-forward "[[:digit:]]+" (line-end-position) t) - (string-to-number (match-string 0))) - cpu-die-temperature - (progn (re-search-forward "temperature: \\([[:digit:]]+\\.[[:digit:]]+\\)" nil t) - (string-to-number (match-string 1)))) + (setq + fan-speed + (save-match-data + (re-search-forward "[[:digit:]]+" (line-end-position) t) + (string-to-number (match-string 0))) + cpu-die-temperature + (save-match-data + (re-search-forward + (rx-to-string + (list + 'seq + "temperature: " + (list + 'group + (list 'one-or-more 'digit) + ?. + (list 'one-or-more 'digit))) + t) + nil t) + (string-to-number (match-string 1)))) ;; NOTE: Now battery charge information (erase-buffer) (call-process "system_profiler" nil t nil "SPPowerDataType") (goto-char (point-min)) - (re-search-forward "Fully Charged: \\(.+\\)$" nil t) - (setf fullp (match-string-no-properties 1)) - (re-search-forward "Charging: \\(.+\\)$" nil t) - (setf charging (match-string-no-properties 1)) - (re-search-forward "Full Charge Capacity (mAh): \\([[:digit:]]+\\)$" nil t) - (setf full-capacity (string-to-number (match-string-no-properties 1))) - (re-search-forward "State of Charge (%): \\([[:digit:]]+\\)" nil t) - (setf remain (string-to-number (match-string-no-properties 1))) - (re-search-forward "Cycle Count: \\(.+\\)$" nil t) - (setf cycle (string-to-number (match-string-no-properties 1))) - (re-search-forward "Condition: \\(.+\\)$" nil t) - (setf condition (match-string-no-properties 1)) - (re-search-forward "Connected: \\(.+\\)$" nil t) - (setf connected (match-string-no-properties 1)) -;; NOTE: Now battery temperature - (erase-buffer) - (call-process "ioreg" nil t nil "-n" "AppleSmartBattery" "-r") - (goto-char (point-min)) - (re-search-forward "Temperature..=." nil t) - (re-search-forward "[[:digit:]]+" nil t) - (setf battery-temp - (/ (string-to-number (match-string-no-properties 0)) - 100.0))) + (save-match-data + (re-search-forward "Fully Charged: \\(.+\\)$" nil t) + (setq fullp (match-string-no-properties 1)) + (re-search-forward "Charging: \\(.+\\)$" nil t) + (setq charging (match-string-no-properties 1)) + (re-search-forward + "Full Charge Capacity (mAh): \\([[:digit:]]+\\)$" nil t) + (setq + full-capacity + (string-to-number (match-string-no-properties 1))) + (re-search-forward + "State of Charge (%): \\([[:digit:]]+\\)" nil t) + (setq + remain + (string-to-number (match-string-no-properties 1))) + (re-search-forward "Cycle Count: \\(.+\\)$" nil t) + (setq + cycle + (string-to-number (match-string-no-properties 1))) + (re-search-forward "Condition: \\(.+\\)$" nil t) + (setq condition (match-string-no-properties 1)) + (re-search-forward "Connected: \\(.+\\)$" nil t) + (setq connected (match-string-no-properties 1)) + ;; NOTE: Now battery temperature + (erase-buffer) + (call-process "ioreg" nil t nil "-n" + "AppleSmartBattery" "-r") + (goto-char (point-min)) + (re-search-forward "Temperature..=." nil t) + (re-search-forward "[[:digit:]]+" nil t) + (setq battery-temp + (/ (string-to-number (match-string-no-properties 0)) + 100.0)))) (message (concat (format "fan: %d, temp: %s, battery temp: %.2f" fan-speed cpu-die-temperature battery-temp) "\n" - (format "Full: %d, remaining: %d%s, fullp: %s, charging: %s, connected: %s, cycles: %d, condition: %s" - full-capacity remain "%%" fullp charging connected cycle condition))))) + (format + "Full: %d, remaining: %d%s, fullp: %s, charging: %s, \ +connected: %s, cycles: %d, condition: %s" + full-capacity remain "%%" fullp charging connected cycle + condition))))) ((equal arg (list 4)) (list-timers)) (t (user-error "Unsupported ARG: %S" arg)))) @@ -83,7 +138,8 @@ If ARG is '(16), view the battery information." (define-key map (vector ?t) 'repeat) map)) -(define-obsolete-function-alias 'durand-view-timers 'durand-view-timers-or-temps +(define-obsolete-function-alias 'durand-view-timers + 'durand-view-timers-or-temps "2020-09-02" "View the list of timers.") ;;;###autoload @@ -152,23 +208,26 @@ See the documentation for `durand-open-object' for the formats of targets.") (setq durand-open-targets - (list (list "safari" "open" "-a" "Safari" - (list "https://www.youtube.com" - "https://www.gmail.com" - "https://www.facebook.com" - "https://protesilaos.com" - "https://wmail1.cc.ntu.edu.tw/rc/?_task=mail&_mbox=INBOX" - "https://dictionary.christian-steinert.de/#home" - ;; "https://wmail1.cc.ntu.edu.tw/index.php?url=https%3A%2F%2Fwmail1.cc.ntu.edu.tw%2F" - )) - (list "terminal" "open" "-a" "Terminal" (list - "/Users/durand/Desktop/Centre/Vidéos/" - "/Users/durand/Desktop/Centre/Musique/" - "/Users/durand/Downloads/")) - (list "messenger" "open" "-a" "Messenger") - (list "temp d'écran" "open" "-b" - "com.apple.systempreferences" - "/System/Library/PreferencePanes/ScreenTime.prefPane"))) + (list + (list + "safari" "open" "-a" "Safari" + (list + "https://www.youtube.com" + "https://www.gmail.com" + "https://www.facebook.com" + "https://protesilaos.com" + "https://wmail1.cc.ntu.edu.tw/rc/?_task=mail&_mbox=INBOX" + "https://dictionary.christian-steinert.de/#home" + )) + (list "terminal" "open" "-a" "Terminal" + (list + "/Users/durand/Desktop/Centre/Vidéos/" + "/Users/durand/Desktop/Centre/Musique/" + "/Users/durand/Downloads/")) + (list "messenger" "open" "-a" "Messenger") + (list "temp d'écran" "open" "-b" + "com.apple.systempreferences" + "/System/Library/PreferencePanes/ScreenTime.prefPane"))) ;;;###autoload (defun durand-target-extra-arg (target) @@ -224,25 +283,25 @@ options to choose from." (extra-arg-slots (durand-target-extra-arg commands)) (extra-arg (cond (arg - (mapcar (lambda (extra-arg-slot) - (cond - ((eq extra-arg-slot -1) - (read-string "Extra argument: ")) - ((consp extra-arg-slot) - (completing-read - "Extra argument: " extra-arg-slot)))) - extra-arg-slots))))) + (mapcar + (lambda (extra-arg-slot) + (cond + ((eq extra-arg-slot -1) + (read-string "Extra argument: ")) + ((consp extra-arg-slot) + (completing-read + "Extra argument: " extra-arg-slot)))) + extra-arg-slots))))) (setq commands (durand-replace-extra-args commands extra-arg)) (make-process :name "durand-open" :buffer nil :command commands))) -;;; C-c o => 3 111 +;; C-c o => 3 111 (define-key global-map (vector 3 111) #'durand-open-object) (define-key global-map (vector ?\H-o) #'durand-open-object) -;;; Convert downloaded videos from youtube to the URL again and copy -;;; the result. +;;; Convert youtube videos to URL ;;;###autoload (defun durand-convert-youtube-video-to-url (video-name) @@ -292,7 +351,8 @@ options to choose from." (cond ((re-search-forward "^\\s-*$" (line-end-position) t) (forward-line 1))) - (while (not (re-search-forward "^\\s-*$" (line-end-position) t)) + (while (not + (re-search-forward "^\\s-*$" (line-end-position) t)) (forward-line 1)) (setq arg (1- arg)))) (t @@ -300,7 +360,8 @@ options to choose from." (cond ((re-search-forward "^\\s-*$" (line-end-position) t) (forward-line -1))) - (while (not (re-search-forward "^\\s-*$" (line-end-position) t)) + (while (not + (re-search-forward "^\\s-*$" (line-end-position) t)) (forward-line -1)) (setq arg (1+ arg))))) (setq pos (point))) @@ -377,3 +438,6 @@ If ARG is non-zero and the second bit is non-zero, toggle ;;; Press 'v' to scroll (define-key view-mode-map (vector ?v) #'View-scroll-page-forward) + +(provide 'view-conf) +;;; view-conf.el ends here -- cgit v1.2.3-18-g5258