utils.el 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. (defun wi-expand-file-names (files)
  2. "Expand FILES."
  3. (mapcar (lambda (file) (expand-file-name file)) files))
  4. ;; See <https://lists.gnu.org/archive/html/emacs-devel/2017-12/msg00017.html>.
  5. (defun wi-git-log (&optional repo commit)
  6. "Check REPO for COMMIT and if it exists, display its commit message.
  7. Interactively, prompt for REPO, defaulting to emacs-master, and
  8. for COMMIT, defaulting to the commit hash at point."
  9. (interactive "p")
  10. (let* ((git-dir (if repo
  11. (read-directory-name
  12. "Repo: " "/mnt/data/steve/git/"
  13. nil t "emacs-master")
  14. "/mnt/data/steve/git/emacs-master"))
  15. (commit0
  16. (or commit
  17. (read-string "Commit: " nil nil (word-at-point))))
  18. (default-directory git-dir)
  19. (output-buffer (get-buffer-create "*git log*"))
  20. (proc (progn
  21. (with-current-buffer output-buffer (erase-buffer))
  22. (call-process "git" nil output-buffer nil
  23. "branch" "--contains" commit0))))
  24. (when proc
  25. (with-current-buffer output-buffer
  26. (goto-char (point-min))
  27. (unless (looking-at "[ *]")
  28. (user-error "%s is not on branch %s" commit0
  29. (file-name-base git-dir)))
  30. (insert "Branches:\n")
  31. (goto-char (point-max))
  32. (call-process "git" nil output-buffer nil "log" "-1" commit0)
  33. (pop-to-buffer output-buffer)))))
  34. (defun string-to-symbols (str)
  35. "Convert a STR string (for example \"ℕ₃₂\") to a list of characters (8469 (Br . Bl) 8323 (Br . Bl) 8322) suited for command `prettify-symbols-mode'."
  36. (let ((chars (string-to-list str)))
  37. `(,(car chars)
  38. ,@(apply 'append (mapcar (lambda (char)
  39. (list '(Br . Bl) char))
  40. (cdr chars))))))
  41. (defun delete-current-buffer-file ()
  42. "Delete the current buffer and the file connected with it"
  43. (interactive)
  44. (let ((filename (buffer-file-name))
  45. (buffer (current-buffer))
  46. (name (buffer-name)))
  47. (if (not (and filename (file-exists-p filename)))
  48. (kill-buffer buffer)
  49. (when (yes-or-no-p "Are you sure this file should be removed? ")
  50. (delete-file filename)
  51. (kill-buffer buffer)
  52. (message "File '%s' successfully removed" filename)))))
  53. (defun wi-buffer-major-mode (buffer)
  54. "Return `major-mode' of BUFFER."
  55. (cdr (assoc 'major-mode (buffer-local-variables buffer))))
  56. (defun wi-buffers-similar-major-mode ()
  57. "Return buffer with similar `major-mode' as in current buffer."
  58. (-filter (lambda (buffer)
  59. (string-equal (wi-buffer-major-mode (current-buffer))
  60. (wi-buffer-major-mode buffer)))
  61. (buffer-list)))
  62. (defun wi-prettify-mjru-network ()
  63. (interactive)
  64. (message
  65. (mapconcat 'identity
  66. (mapcar (lambda (host)
  67. (mapconcat 'identity
  68. (mapcar 'char-to-string
  69. (delete '(Br . Bl)
  70. (cdr host)))
  71. ""))
  72. (-filter (lambda (net)
  73. (string= (car net) (thing-at-point 'filename)))
  74. mjru-prettify-hosts))
  75. "\n")))