From 02e6c91a88ee7af4b85aae8e99b4ee89b1562b75 Mon Sep 17 00:00:00 2001 From: Lars Andersen Date: Sat, 5 Sep 2015 12:52:38 +0200 Subject: [PATCH] Fix clean-ns sometimes deleting metadata If the file started with a comment, clean-ns, would fail to retrieve the metadata. Fixes clojure-emacs/clj-refactor.el#223 --- src/refactor_nrepl/ns/pprint.clj | 7 +++---- test/resources/ns2_meta.clj | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/refactor_nrepl/ns/pprint.clj b/src/refactor_nrepl/ns/pprint.clj index b713b252..b7b1eb7d 100644 --- a/src/refactor_nrepl/ns/pprint.clj +++ b/src/refactor_nrepl/ns/pprint.clj @@ -2,8 +2,7 @@ (:require [clojure [pprint :refer [pprint]] [string :as str]] - [refactor-nrepl.ns.helpers :refer [prefix-form?]] - [refactor-nrepl.util :as util])) + [refactor-nrepl.ns.helpers :as helpers :refer [prefix-form?]])) (defn- libspec-vectors-last [libspecs] (vec (concat (remove sequential? libspecs) @@ -85,8 +84,8 @@ avoid duplication we have to remove some of the keys in the metadata map before printing." [path] - (let [meta? (-> path slurp util/get-next-sexp (.replaceFirst "\\^\\{" "\\{") - read-string second)] + (let [meta? (-> path slurp (.replaceFirst "\\^\\{" "\\{") + helpers/ns-form-from-string second)] (when (map? meta?) meta?))) diff --git a/test/resources/ns2_meta.clj b/test/resources/ns2_meta.clj index da1368fd..8cffa2e8 100644 --- a/test/resources/ns2_meta.clj +++ b/test/resources/ns2_meta.clj @@ -1,3 +1,10 @@ +;; =========================================================================== +;; +;; Copyright (c) Example Inc. All rights reserved. +;; +;; https://github.com/clojure-emacs/clj-refactor.el/issues/223 +;; +;; =========================================================================== (ns ^{:author "Trurl and Klapaucius" :doc "test ns with meta"} resources.ns2-meta