diff options
author | Nic Ferrier <nferrier@ferrier.me.uk> | 2014-02-02 22:51:53 +0000 |
---|---|---|
committer | Nic Ferrier <nferrier@ferrier.me.uk> | 2014-02-02 22:51:53 +0000 |
commit | f6a8c7af44d8faab58b892b0dcdec6778da18f85 (patch) | |
tree | 2817789084f809c6393c555a1baac1c4c6161e01 | |
parent | 544c30d0da664acb6b1d0db7b98e25396c8b40f6 (diff) |
add a new indent function that works for everyone
-rw-r--r-- | README.creole | 9 | ||||
-rw-r--r-- | noflet.el | 17 |
2 files changed, 22 insertions, 4 deletions
diff --git a/README.creole b/README.creole index b7c4d8a..5a1f9d7 100644 --- a/README.creole +++ b/README.creole @@ -2,6 +2,9 @@ {{{noflet}}} is dynamic, local, advice for Emacs-Lisp code. +{{{noflet}}} also has an Emacs indentation function for {{{flet}}} +like macros. + It's great for test code when you need to mock another function. This is useful for definining functions that overide a base definition @@ -49,6 +52,12 @@ definition of these common Emacs functions. This overrides {{{find-file}}} to set a local variable. There are surely better ways to do it than this but it illustrates the point. + +=== Lexical version === + +Because we include a good indenting function we also include a lexical +{{{flet}}}. It's just a wrapper for {{{cl-flet}}}. + === todo === It would be nice to have a noflet that could work with Emacs/CL style @@ -4,7 +4,7 @@ ;; Author: Nic Ferrier <nferrier@ferrier.me.uk> ;; Keywords: lisp -;; Version: 0.0.10 +;; Version: 0.0.11 ;; Url: https://github.com/nicferrier/emacs-noflet ;; This program is free software; you can redistribute it and/or modify @@ -102,7 +102,16 @@ name." (progn ,@fsets) ,@forms) (progn ,@fresets))))) - + +(defun noflet-indent-func (pos &rest state) + "Deliver sensible indenting for flet like functions." + ;; (message "pos: %s state: %s" pos state) + (save-excursion + (goto-char (elt (car state) 1)) + (+ 2 + (- (point) + (line-beginning-position))))) + (defmacro noflet (bindings &rest body) "Make local function BINDINGS allowing access to the original. @@ -129,7 +138,7 @@ If new bindings are introduced the binding is discarded upon exit. Even with new bindings there is still a `this-fn'. It points to `noflet|base' for all new bindings." (declare (debug ((&rest (cl-defun)) cl-declarations body)) - (indent ((&whole 4 &rest (&whole 1 &lambda &body)) &body))) + (indent noflet-indent-func)) (apply 'noflet|expand bindings body)) (defmacro nolexflet (bindings &rest body) @@ -139,7 +148,7 @@ This only exists as an alias for `cl-flet' because Emacs maintainers refuse to add the correct indentation spec to `cl-flet'." (declare (debug ((&rest (cl-defun)) cl-declarations body)) - (indent ((&whole 4 &rest (&whole 1 &lambda &body)) &body))) + (indent noflet-indent-func)) `(cl-flet ,bindings ,@body)) (provide 'noflet) |