diff options
author | Alan Pearce | 2014-08-09 10:17:48 +0100 |
---|---|---|
committer | Alan Pearce | 2014-08-09 10:17:48 +0100 |
commit | 03be1651e1dc1ce28b4f8fa3a619d7fa1f3453b3 (patch) | |
tree | 62dea78d98e023fa992fa2ac5e56664e3bbcd74f /content/post | |
parent | 8fcfe5b8eee07bbccbdcca633c0c5c68492bdaea (diff) | |
download | website-03be1651e1dc1ce28b4f8fa3a619d7fa1f3453b3.tar.lz website-03be1651e1dc1ce28b4f8fa3a619d7fa1f3453b3.tar.zst website-03be1651e1dc1ce28b4f8fa3a619d7fa1f3453b3.zip |
New post: Cedit and Paredit
Diffstat (limited to 'content/post')
-rw-r--r-- | content/post/cedit-and-paredit.md | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/content/post/cedit-and-paredit.md b/content/post/cedit-and-paredit.md new file mode 100644 index 0000000..ff6cce3 --- /dev/null +++ b/content/post/cedit-and-paredit.md | |||
@@ -0,0 +1,44 @@ | |||
1 | +++ | ||
2 | Categories = ["Development", "Emacs"] | ||
3 | Description = "Cedit and paredit for structural editing" | ||
4 | Tags = ["Development", "Emacs"] | ||
5 | title = "Cedit and Paredit" | ||
6 | date = 2014-08-04T07:10:14Z | ||
7 | +++ | ||
8 | |||
9 | I recently discovered [cedit][], which provides some structural | ||
10 | commands for editing c-like languages. (See this | ||
11 | [Emacs Rocks! episode][e14] if you're not familiar with the concept: | ||
12 | it introduces [paredit][], a structural editing mode for lisps). | ||
13 | |||
14 | So, it deals with curly braces and semicolons, keeping things balanced | ||
15 | and correct as show in its [screencast][cedit-readme]. It mentions that it | ||
16 | integrates with [paredit][] rather than duplicating *all* its | ||
17 | functionality. After setting up cedit, I decided to try enabling | ||
18 | paredit alongside cedit and disabling autopair. Once I did, | ||
19 | however, I noticed an annoying formatting issue: If I were to type | ||
20 | `foo` and then `(`, paredit would format this as `foo ()`, which makes | ||
21 | sense, considering that paredit is written for lisps — s-expressions | ||
22 | are usually separated by spaces — but not so much for c-like languages. | ||
23 | |||
24 | I was thinking about disabling paredit and going back to autopair, | ||
25 | when I decided to look through the configuration variables for | ||
26 | paredit. Turns out it provides | ||
27 | `paredit-space-for-delimiter-predicates`, which is a list of functions | ||
28 | that control whether a space should be inserted. So, solving the | ||
29 | formatting issue turned out to be pretty simple: | ||
30 | |||
31 | {{% highlight cl %}} | ||
32 | (defun ap/cedit-space-delimiter-p (endp delimiter) | ||
33 | "Don't insert a space before delimiters in c-style modes" | ||
34 | (not cedit-mode)) | ||
35 | (add-to-list 'paredit-space-for-delimiter-predicates #'ap/cedit-space-delimiter-p) | ||
36 | {{% /highlight %}} | ||
37 | |||
38 | Hopefully that saves someone some time if they try to use the two | ||
39 | together. | ||
40 | |||
41 | [cedit]: https://github.com/zk-phi/cedit | ||
42 | [cedit-readme]: https://github.com/zk-phi/cedit#readme | ||
43 | [e14]: http://emacsrocks.com/e14.html | ||
44 | [paredit]: http://www.emacswiki.org/emacs/ParEdit | ||