From 1e160edd4ce6c7fa1181cbe311594b9b6d819e1a Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Wed, 3 May 2017 10:03:46 +0200 Subject: Update shortcode syntax --- content/post/cedit-and-paredit.md | 4 +-- content/post/emacs-package-archive-statistics.md | 40 ++++++++++++------------ 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'content/post') diff --git a/content/post/cedit-and-paredit.md b/content/post/cedit-and-paredit.md index 09ed176..a8b65a1 100644 --- a/content/post/cedit-and-paredit.md +++ b/content/post/cedit-and-paredit.md @@ -28,12 +28,12 @@ paredit. Turns out it provides that control whether a space should be inserted. So, solving the formatting issue turned out to be pretty simple: -{{% highlight cl %}} +{{< highlight cl >}} (defun ap/cedit-space-delimiter-p (endp delimiter) "Don't insert a space before delimiters in c-style modes" (not cedit-mode)) (add-to-list 'paredit-space-for-delimiter-predicates #'ap/cedit-space-delimiter-p) -{{% /highlight %}} +{{< /highlight >}} Hopefully that saves someone some time if they try to use the two together. diff --git a/content/post/emacs-package-archive-statistics.md b/content/post/emacs-package-archive-statistics.md index 4bfa91e..5f74f18 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 configuration. Whenever I opened my `Cask` file, I wondered if I really was using all the sources I had defined: -{{% highlight cl %}} +{{< highlight cl >}} (source gnu) (source marmalade) (source melpa) (source melpa-stable) (source org) -{{% /highlight %}} +{{< /highlight >}} It seemed quite strange that we have so many package repositories in 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. I found [how to get a list of installed packages][], but that just gives a list: -{{% highlight cl %}} +{{< highlight cl >}} (ace-jump-mode ag auto-compile auto-indent-mode autopair ...) -{{% /highlight %}} +{{< /highlight >}} I needed to get more information about those packages. I looked at where `list-packages` gets that information from. It seems that `package-archive-contents` is a list of cons cells: -{{% highlight cl %}} +{{< highlight cl >}} (org-plus-contrib . [(20140714) nil "Outline-based notes management and organizer" tar "org"]) -{{% /highlight %}} +{{< /highlight >}} Then created a function to loop over the contents of `package-activated-list`, retrieving the corresponding contents of `package-archive-contents`: -{{% highlight cl %}} +{{< highlight cl >}} (defun package-list-installed () (loop for pkg in package-activated-list collect (assq pkg package-archive-contents))) -{{% /highlight %}} +{{< /highlight >}} This generates a list of arrays from `package-archive-contents`. There are some helper functions in package.el such as @@ -74,11 +74,11 @@ There are some helper functions in package.el such as needed. I happened to be using a pretest version of Emacs at the time and didn't know that it's not in 24.3, so I just made sure it was defined: -{{% highlight cl %}} +{{< highlight cl >}} (if (not (fboundp #'package-desc-archive)) (defsubst package-desc-archive (desc) (aref desc (1- (length desc))))) -{{% /highlight %}} +{{< /highlight >}} Weirdly, some of the arrays (seemingly the ones from the [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 installed packages from `package-list-installed` and update a count for each archive: -{{% highlight cl %}} +{{< highlight cl >}} (defun package-archive-stats () (let ((archives (makehash)) (assoc '())) @@ -101,32 +101,32 @@ for each archive: (let ((pkg-arc (package-desc-archive (cdr pkg)))) (incf (gethash pkg-arc archives))))) assoc)) -{{% /highlight %}} +{{< /highlight >}} Running this gives a list of cons cells: -{{% highlight cl %}} +{{< highlight cl >}} (("gnu" . 0) ("org" . 1) ("melpa-stable" . 2) ("melpa" . 106) ("marmalade" . 1)) -{{% /highlight %}} +{{< /highlight >}} I wrapped it in an interactive function so that I could check the numbers quickly: -{{% highlight cl %}} +{{< highlight cl >}} (defun package-show-archive-stats () (interactive) (message "%s" (package-archive-stats))) -{{% /highlight %}} +{{< /highlight >}} With that, I removed `(source gnu)` from my `Cask` file. Now I had another question. What package was installed from [marmalade][]? In the lisp fashion, I created yet another function: -{{% highlight cl %}} +{{< highlight cl >}} (defun package-show-installed-from-archive (archive) (interactive (list (helm-comp-read "Archive: " (mapcar #'car package-archives) :must-match t))) @@ -136,15 +136,15 @@ the lisp fashion, I created yet another function: (if (called-interactively-p) (message "%s" from-arc) from-arc))) -{{% /highlight %}} +{{< /highlight >}} (Non-helm users can replace `helm-comp-read` with `ido-completing-read` or similar) Running this with the argument `"marmalade"` gives: -{{% highlight cl %}} +{{< highlight cl >}} (php-extras) -{{% /highlight %}} +{{< /highlight >}} I checked on [MELPA Stable][] and [MELPA][], but it's not available there. Given that I use [php-extras][] quite a bit at work, I can't remove -- cgit 1.4.1