diff options
author | Alan Pearce | 2018-06-07 13:55:17 +0200 |
---|---|---|
committer | Alan Pearce | 2018-06-07 13:55:17 +0200 |
commit | 10dded485e1c2627575b2b9e21dfaabc31ee07f3 (patch) | |
tree | b3f0369bae776cd556078225fc446c10165f8624 /content/post/emacs-package-archive-statistics.md | |
parent | 956bf3a40be61da586bd5178a3868ca037eebbe8 (diff) | |
download | website-10dded485e1c2627575b2b9e21dfaabc31ee07f3.tar.lz website-10dded485e1c2627575b2b9e21dfaabc31ee07f3.tar.zst website-10dded485e1c2627575b2b9e21dfaabc31ee07f3.zip |
Use code fences instead of template tags for syntax highlighting
Diffstat (limited to 'content/post/emacs-package-archive-statistics.md')
-rw-r--r-- | content/post/emacs-package-archive-statistics.md | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/content/post/emacs-package-archive-statistics.md b/content/post/emacs-package-archive-statistics.md index 5f74f18..2275c9a 100644 --- a/content/post/emacs-package-archive-statistics.md +++ b/content/post/emacs-package-archive-statistics.md | |||
@@ -10,13 +10,13 @@ I use [cask][] for managing the dependencies of my Emacs | |||
10 | configuration. Whenever I opened my `Cask` file, I wondered if I | 10 | configuration. Whenever I opened my `Cask` file, I wondered if I |
11 | really was using all the sources I had defined: | 11 | really was using all the sources I had defined: |
12 | 12 | ||
13 | {{< highlight cl >}} | 13 | ```elisp |
14 | (source gnu) | 14 | (source gnu) |
15 | (source marmalade) | 15 | (source marmalade) |
16 | (source melpa) | 16 | (source melpa) |
17 | (source melpa-stable) | 17 | (source melpa-stable) |
18 | (source org) | 18 | (source org) |
19 | {{< /highlight >}} | 19 | ``` |
20 | 20 | ||
21 | It seemed quite strange that we have so many package repositories in | 21 | It seemed quite strange that we have so many package repositories in |
22 | the Emacs world and I'm not even using all of them. I find this state | 22 | the Emacs world and I'm not even using all of them. I find this state |
@@ -44,29 +44,29 @@ decided to try to figure out how to generate some usage statistics. | |||
44 | I found [how to get a list of installed packages][], but that just gives | 44 | I found [how to get a list of installed packages][], but that just gives |
45 | a list: | 45 | a list: |
46 | 46 | ||
47 | {{< highlight cl >}} | 47 | ```elisp |
48 | (ace-jump-mode ag auto-compile auto-indent-mode autopair ...) | 48 | (ace-jump-mode ag auto-compile auto-indent-mode autopair ...) |
49 | {{< /highlight >}} | 49 | ``` |
50 | 50 | ||
51 | I needed to get more information about those packages. I looked at | 51 | I needed to get more information about those packages. I looked at |
52 | where `list-packages` gets that information from. It seems that | 52 | where `list-packages` gets that information from. It seems that |
53 | `package-archive-contents` is a list of cons cells: | 53 | `package-archive-contents` is a list of cons cells: |
54 | 54 | ||
55 | {{< highlight cl >}} | 55 | ```elisp |
56 | (org-plus-contrib . | 56 | (org-plus-contrib . |
57 | [(20140714) | 57 | [(20140714) |
58 | nil "Outline-based notes management and organizer" tar "org"]) | 58 | nil "Outline-based notes management and organizer" tar "org"]) |
59 | {{< /highlight >}} | 59 | ``` |
60 | 60 | ||
61 | Then created a function to loop over the contents of | 61 | Then created a function to loop over the contents of |
62 | `package-activated-list`, retrieving the corresponding contents of | 62 | `package-activated-list`, retrieving the corresponding contents of |
63 | `package-archive-contents`: | 63 | `package-archive-contents`: |
64 | 64 | ||
65 | {{< highlight cl >}} | 65 | ```elisp |
66 | (defun package-list-installed () | 66 | (defun package-list-installed () |
67 | (loop for pkg in package-activated-list | 67 | (loop for pkg in package-activated-list |
68 | collect (assq pkg package-archive-contents))) | 68 | collect (assq pkg package-archive-contents))) |
69 | {{< /highlight >}} | 69 | ``` |
70 | 70 | ||
71 | This generates a list of arrays from `package-archive-contents`. | 71 | This generates a list of arrays from `package-archive-contents`. |
72 | There are some helper functions in package.el such as | 72 | There are some helper functions in package.el such as |
@@ -74,11 +74,11 @@ There are some helper functions in package.el such as | |||
74 | needed. I happened to be using a pretest version of Emacs at the time | 74 | needed. I happened to be using a pretest version of Emacs at the time |
75 | and didn't know that it's not in 24.3, so I just made sure it was defined: | 75 | and didn't know that it's not in 24.3, so I just made sure it was defined: |
76 | 76 | ||
77 | {{< highlight cl >}} | 77 | ```elisp |
78 | (if (not (fboundp #'package-desc-archive)) | 78 | (if (not (fboundp #'package-desc-archive)) |
79 | (defsubst package-desc-archive (desc) | 79 | (defsubst package-desc-archive (desc) |
80 | (aref desc (1- (length desc))))) | 80 | (aref desc (1- (length desc))))) |
81 | {{< /highlight >}} | 81 | ``` |
82 | 82 | ||
83 | Weirdly, some of the arrays (seemingly the ones from the | 83 | Weirdly, some of the arrays (seemingly the ones from the |
84 | [org archive][]) had a different length, but the repository/archive was | 84 | [org archive][]) had a different length, but the repository/archive was |
@@ -89,7 +89,7 @@ To generate a list of statistics, I just needed to loop over the | |||
89 | installed packages from `package-list-installed` and update a count | 89 | installed packages from `package-list-installed` and update a count |
90 | for each archive: | 90 | for each archive: |
91 | 91 | ||
92 | {{< highlight cl >}} | 92 | ```elisp |
93 | (defun package-archive-stats () | 93 | (defun package-archive-stats () |
94 | (let ((archives (makehash)) | 94 | (let ((archives (makehash)) |
95 | (assoc '())) | 95 | (assoc '())) |
@@ -101,32 +101,32 @@ for each archive: | |||
101 | (let ((pkg-arc (package-desc-archive (cdr pkg)))) | 101 | (let ((pkg-arc (package-desc-archive (cdr pkg)))) |
102 | (incf (gethash pkg-arc archives))))) | 102 | (incf (gethash pkg-arc archives))))) |
103 | assoc)) | 103 | assoc)) |
104 | {{< /highlight >}} | 104 | ``` |
105 | 105 | ||
106 | Running this gives a list of cons cells: | 106 | Running this gives a list of cons cells: |
107 | 107 | ||
108 | {{< highlight cl >}} | 108 | ```elisp |
109 | (("gnu" . 0) | 109 | (("gnu" . 0) |
110 | ("org" . 1) | 110 | ("org" . 1) |
111 | ("melpa-stable" . 2) | 111 | ("melpa-stable" . 2) |
112 | ("melpa" . 106) | 112 | ("melpa" . 106) |
113 | ("marmalade" . 1)) | 113 | ("marmalade" . 1)) |
114 | {{< /highlight >}} | 114 | ``` |
115 | 115 | ||
116 | I wrapped it in an interactive function so that I could check the | 116 | I wrapped it in an interactive function so that I could check the |
117 | numbers quickly: | 117 | numbers quickly: |
118 | 118 | ||
119 | {{< highlight cl >}} | 119 | ```elisp |
120 | (defun package-show-archive-stats () | 120 | (defun package-show-archive-stats () |
121 | (interactive) | 121 | (interactive) |
122 | (message "%s" (package-archive-stats))) | 122 | (message "%s" (package-archive-stats))) |
123 | {{< /highlight >}} | 123 | ``` |
124 | 124 | ||
125 | With that, I removed `(source gnu)` from my `Cask` file. Now I had | 125 | With that, I removed `(source gnu)` from my `Cask` file. Now I had |
126 | another question. What package was installed from [marmalade][]? In | 126 | another question. What package was installed from [marmalade][]? In |
127 | the lisp fashion, I created yet another function: | 127 | the lisp fashion, I created yet another function: |
128 | 128 | ||
129 | {{< highlight cl >}} | 129 | ```elisp |
130 | (defun package-show-installed-from-archive (archive) | 130 | (defun package-show-installed-from-archive (archive) |
131 | (interactive (list (helm-comp-read "Archive: " (mapcar #'car package-archives) | 131 | (interactive (list (helm-comp-read "Archive: " (mapcar #'car package-archives) |
132 | :must-match t))) | 132 | :must-match t))) |
@@ -136,15 +136,15 @@ the lisp fashion, I created yet another function: | |||
136 | (if (called-interactively-p) | 136 | (if (called-interactively-p) |
137 | (message "%s" from-arc) | 137 | (message "%s" from-arc) |
138 | from-arc))) | 138 | from-arc))) |
139 | {{< /highlight >}} | 139 | ``` |
140 | (Non-helm users can replace `helm-comp-read` with | 140 | (Non-helm users can replace `helm-comp-read` with |
141 | `ido-completing-read` or similar) | 141 | `ido-completing-read` or similar) |
142 | 142 | ||
143 | Running this with the argument `"marmalade"` gives: | 143 | Running this with the argument `"marmalade"` gives: |
144 | 144 | ||
145 | {{< highlight cl >}} | 145 | ```elisp |
146 | (php-extras) | 146 | (php-extras) |
147 | {{< /highlight >}} | 147 | ``` |
148 | 148 | ||
149 | I checked on [MELPA Stable][] and [MELPA][], but it's not available | 149 | I checked on [MELPA Stable][] and [MELPA][], but it's not available |
150 | there. Given that I use [php-extras][] quite a bit at work, I can't remove | 150 | there. Given that I use [php-extras][] quite a bit at work, I can't remove |