about summary refs log tree commit diff stats
path: root/content/post
diff options
context:
space:
mode:
authorAlan Pearce2014-08-09 10:17:48 +0100
committerAlan Pearce2014-08-09 10:17:48 +0100
commit03be1651e1dc1ce28b4f8fa3a619d7fa1f3453b3 (patch)
tree62dea78d98e023fa992fa2ac5e56664e3bbcd74f /content/post
parent8fcfe5b8eee07bbccbdcca633c0c5c68492bdaea (diff)
downloadwebsite-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.md44
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 @@
++++
+Categories = ["Development", "Emacs"]
+Description = "Cedit and paredit for structural editing"
+Tags = ["Development", "Emacs"]
+title = "Cedit and Paredit"
+date = 2014-08-04T07:10:14Z
++++
+
+I recently discovered [cedit][], which provides some structural
+commands for editing c-like languages.  (See this
+[Emacs Rocks! episode][e14] if you're not familiar with the concept:
+it introduces [paredit][], a structural editing mode for lisps).
+
+So, it deals with curly braces and semicolons, keeping things balanced
+and correct as show in its [screencast][cedit-readme]. It mentions that it
+integrates with [paredit][] rather than duplicating *all* its
+functionality.  After setting up cedit, I decided to try enabling
+paredit alongside cedit and disabling autopair.  Once I did,
+however, I noticed an annoying formatting issue: If I were to type
+`foo` and then `(`, paredit would format this as `foo ()`, which makes
+sense, considering that paredit is written for lisps — s-expressions
+are usually separated by spaces — but not so much for c-like languages.
+
+I was thinking about disabling paredit and going back to autopair,
+when I decided to look through the configuration variables for
+paredit.  Turns out it provides
+`paredit-space-for-delimiter-predicates`, which is a list of functions
+that control whether a space should be inserted.  So, solving the
+formatting issue turned out to be pretty simple:
+
+{{% 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 %}}
+
+Hopefully that saves someone some time if they try to use the two
+together.
+
+[cedit]: https://github.com/zk-phi/cedit
+[cedit-readme]: https://github.com/zk-phi/cedit#readme
+[e14]: http://emacsrocks.com/e14.html
+[paredit]: http://www.emacswiki.org/emacs/ParEdit