Skip to content

Commit 526ae54

Browse files
author
Bruce Hauman
committed
Remove Emacs notification support and edit location tracking
Removes all Emacs editor integration features including: - Delete emacs_integration.clj (242 lines) - Remove emacs-buffer-modified-check and highlight-form from pipelines - Remove capture-edit-offsets and edit-locations->offsets functions - Remove :emacs-notify config option from schema and config.clj - Remove :enable-emacs-notifications from tool configurations - Update documentation (CONFIG.md, README.md, PROJECT_SUMMARY.md) - Fix test assertion checking for removed :offsets field
1 parent 21a804c commit 526ae54

File tree

16 files changed

+20
-423
lines changed

16 files changed

+20
-423
lines changed

CONFIG.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@ The timestamp tracking system prevents accidental overwrites when files are modi
6060
- When you want automatic nREPL server management without separate terminal windows
6161
- In CI/CD environments where automatic startup is beneficial
6262

63-
### `:emacs-notify`
64-
Boolean flag to enable Emacs integration notifications.
65-
66-
Emacs notify is only a toy for now... it switches focus to the file
67-
being edited and highlights changes as they happen. There are
68-
probably better ways to handle this with auto-revert and existing
69-
Emacs libraries.
70-
71-
**Prerequisites for Emacs Integration:**
72-
- `emacsclient` must be available in your system PATH
73-
- Emacs server must be running (start with `M-x server-start` or add `(server-start)` to your init file)
74-
- The integration allows the MCP server to communicate with your Emacs editor for enhanced development workflows
75-
7663
### `:scratch-pad-load`
7764
Boolean flag to automatically load the scratch pad on startup (default: `false`).
7865

PROJECT_SUMMARY.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ your-project/
131131

132132
### Configuration Options
133133
- `allowed-directories`: Controls which directories MCP tools can access (security)
134-
- `emacs-notify`: Boolean flag for Emacs integration
135134
- `write-file-guard`: Controls file timestamp tracking behavior (default: `:partial-read`)
136135
- `:partial-read` - Both full and collapsed reads update timestamps (default)
137136
- `:full-read` - Only full reads update timestamps (safest)
@@ -187,7 +186,6 @@ your-project/
187186
### Example Configuration
188187
```edn
189188
{:allowed-directories ["." "src" "test" "resources" "../sibling-project"]
190-
:emacs-notify false
191189
:write-file-guard :partial-read
192190
:cljfmt true
193191
:bash-over-nrepl true

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,6 @@ Configuration is extensively documented [here](doc/CONFIG.md).
10071007
"dev"
10081008
"/absolute/path/to/shared/code"
10091009
"../sibling-project"]
1010-
:emacs-notify false
10111010
:write-file-guard :full-read
10121011
:cljfmt true
10131012
:bash-over-nrepl true

resources/configs/example-tools-config.edn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
;; Example configuration with tools-config
22
{:allowed-directories ["." "src" "test" "resources"]
3-
:emacs-notify false
43
:write-file-guard :partial-read
54
:cljfmt true
65
:bash-over-nrepl true

src/clojure_mcp/config.clj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
:config config
8787
:file-path canonical-path})))))))
8888

89-
(defn process-config [{:keys [allowed-directories emacs-notify write-file-guard cljfmt bash-over-nrepl nrepl-env-type] :as config} user-dir]
89+
(defn process-config [{:keys [allowed-directories write-file-guard cljfmt bash-over-nrepl nrepl-env-type] :as config} user-dir]
9090
(let [ud (io/file user-dir)]
9191
(assert (and (.isAbsolute ud) (.isDirectory ud)))
9292
(when (some? write-file-guard)
@@ -104,8 +104,6 @@
104104
(keep #(relative-to user-dir %))
105105
distinct
106106
vec))
107-
(some? (:emacs-notify config))
108-
(assoc :emacs-notify (boolean (:emacs-notify config)))
109107
(some? (:cljfmt config))
110108
(assoc :cljfmt (boolean (:cljfmt config)))
111109
(some? (:bash-over-nrepl config))
@@ -166,9 +164,6 @@
166164
(defn get-allowed-directories [nrepl-client-map]
167165
(get-config nrepl-client-map :allowed-directories))
168166

169-
(defn get-emacs-notify [nrepl-client-map]
170-
(get-config nrepl-client-map :emacs-notify))
171-
172167
(defn get-nrepl-user-dir [nrepl-client-map]
173168
(get-config nrepl-client-map :nrepl-user-dir))
174169

src/clojure_mcp/config/schema.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@
260260

261261
;; Core configuration
262262
[:allowed-directories {:optional true} [:sequential Path]]
263-
[:emacs-notify {:optional true} :boolean]
264263
[:write-file-guard {:optional true} [:enum :full-read :partial-read false]]
265264
[:cljfmt {:optional true} :boolean]
266265
[:bash-over-nrepl {:optional true} :boolean]

src/clojure_mcp/tools/file_edit/pipeline.clj

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
[clojure-mcp.tools.file-write.core :as file-write-core]
1010
[clojure-mcp.tools.agent-tool-builder.file-changes :as file-changes]
1111
[clojure-mcp.tools.unified-read-file.file-timestamps :as file-timestamps]
12-
[clojure-mcp.utils.emacs-integration :as emacs]
1312
[clojure-mcp.config :as config]
1413
[clojure-mcp.linting :as linting]
1514
[clojure.spec.alpha :as s]
@@ -82,30 +81,6 @@
8281
ctx))
8382
ctx)))
8483

85-
(defn capture-file-edit-offsets
86-
"Captures the position offsets of the edited region in a file.
87-
This function calculates character offsets for the edited region for highlighting.
88-
89-
Requires ::form-pipeline/source and ::old-string in the context.
90-
Adds ::form-pipeline/offsets to the context when successful."
91-
[ctx]
92-
(try
93-
(let [source (::form-pipeline/source ctx)
94-
old-string (::old-string ctx)]
95-
(if (and source old-string (not-empty old-string))
96-
(let [start-offset (when-let [so (str/index-of source old-string)]
97-
(inc so))
98-
end-offset (when start-offset (+ start-offset (count old-string)))]
99-
(if (and start-offset end-offset)
100-
(assoc ctx ::form-pipeline/offsets [start-offset end-offset])
101-
ctx))
102-
ctx))
103-
(catch Exception e
104-
;; Don't fail the pipeline if offsets can't be captured, just log it
105-
;; This allows non-Emacs workflows to continue
106-
(log/error e (str "Warning: Failed to capture edit offsets -" (.getMessage e)))
107-
ctx)))
108-
10984
;; This function is no longer needed - we'll use form-pipeline/highlight-form instead
11085

11186
;; Using update-file-timestamp from form-edit/pipeline instead
@@ -134,12 +109,10 @@
134109
;; Pipeline for existing file edit
135110
(form-pipeline/thread-ctx
136111
initial-ctx
137-
form-pipeline/emacs-buffer-modified-check
138112
form-pipeline/load-source ;; Load existing file
139113
file-changes/capture-original-file-content ;; Capture original content
140114
form-pipeline/check-file-modified ;; Check if file modified since last read
141115
validate-edit ;; Validate the edit (uniqueness, etc.)
142-
capture-file-edit-offsets ;; Capture offsets for highlight
143116
perform-edit ;; Perform the actual edit
144117
;; Only lint/repair Clojure files
145118
(fn [ctx]
@@ -156,8 +129,7 @@
156129
ctx
157130
(-> ctx
158131
form-pipeline/save-file
159-
form-pipeline/update-file-timestamp
160-
form-pipeline/highlight-form)))))) ;; Update the timestamp after save ;; Update the timestamp after save
132+
form-pipeline/update-file-timestamp))))))
161133

162134
;; Format result for tool consumption
163135
(defn format-result
@@ -197,9 +169,9 @@
197169
;; Create a test file
198170
(spit test-file "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n")
199171

200-
;; Test the pipeline with simple edit and Emacs highlighting enabled
201-
(def config {:enable-emacs-notifications true})
202-
(def result (file-edit-pipeline test-file "Line 3" "Line 3 - EDITED" config))
172+
;; Test the pipeline with simple edit
173+
(def config {})
174+
(def result (file-edit-pipeline test-file "Line 3" "Line 3 - EDITED" nil config))
203175
(format-result result)
204176

205177
;; Test the pipeline with error (non-unique match)

src/clojure_mcp/tools/file_edit/tool.clj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
(defn create-file-edit-tool
1313
"Creates the file-edit tool configuration"
1414
[nrepl-client-atom]
15-
(let [client @nrepl-client-atom
16-
emacs-notify (config/get-emacs-notify client)]
17-
{:tool-type :file-edit
18-
:nrepl-client-atom nrepl-client-atom
19-
:enable-emacs-notifications emacs-notify}))
15+
{:tool-type :file-edit
16+
:nrepl-client-atom nrepl-client-atom})
2017

2118
;; Implement the required multimethods for the file-edit tool
2219
(defmethod tool-system/tool-name :file-edit [_]

src/clojure_mcp/tools/form_edit/combined_edit_tool.clj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@
2828

2929
;; Tool creation function
3030
(defn create-edit-form-tool
31-
"Creates the tool configuration for unified form editing operations.
32-
Automatically inherits emacs notification preferences from the client."
31+
"Creates the tool configuration for unified form editing operations."
3332
[nrepl-client-atom]
34-
(let [client @nrepl-client-atom
35-
emacs-notify (config/get-emacs-notify client)]
36-
{:tool-type :clojure-edit-form
37-
:nrepl-client-atom nrepl-client-atom
38-
:enable-emacs-notifications emacs-notify}))
33+
{:tool-type :clojure-edit-form
34+
:nrepl-client-atom nrepl-client-atom})
3935

4036
;; Tool name implementation
4137
(defmethod tool-system/tool-name :clojure-edit-form [_]

src/clojure_mcp/tools/form_edit/pipeline.clj

Lines changed: 3 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
(:require
66
[clojure-mcp.tools.form-edit.core :as core]
77
[clojure-mcp.tools.agent-tool-builder.file-changes :as file-changes]
8-
[clojure-mcp.utils.emacs-integration :as emacs]
98
[clojure-mcp.utils.diff :as diff-utils]
109
[clojure-mcp.tools.unified-read-file.file-timestamps :as file-timestamps]
1110
[clojure-mcp.config :as config]
@@ -95,23 +94,6 @@
9594
(assoc ::source (:content result))
9695
(assoc ::old-content (:content result))))))
9796

98-
(defn emacs-buffer-modified-check
99-
"Check if the emacs buffer is modified and saves it. When used before
100-
check-file-modifed, it will trigger the modification error.
101-
102-
A modified buffer is another level to check for file modifications.
103-
104-
Marking it as modified. This in turn will trigger the check last modified
105-
to error out requiring the LLM to read the file before editing."
106-
[ctx]
107-
(let [file-path (::file-path ctx)
108-
config (::config ctx)]
109-
(if (and (emacs/config-enables-emacs-notifications? config)
110-
(emacs/save-emacs-buffer-if-modified file-path))
111-
;; prevent race condition of write and then relying on read
112-
(assoc ctx ::file-modifed true)
113-
ctx)))
114-
11597
(defn check-file-modified
11698
"Checks if the file has been modified since last read.
11799
Returns error if modified without being read again.
@@ -207,25 +189,6 @@
207189
{::error true
208190
::message (str "Error parsing source: " (.getMessage e))})))
209191

210-
(defn capture-edit-offsets
211-
"Captures the position offsets of the current zipper location.
212-
This should be called immediately after editing operations while position information is valid.
213-
214-
Requires ::zloc in the context.
215-
Adds ::offsets to the context when successful."
216-
[ctx]
217-
(try
218-
(let [zloc (::zloc ctx)
219-
positions (z/position-span zloc)
220-
output-source (or (::output-source ctx) (z/root-string zloc))
221-
offsets (core/zloc-offsets output-source positions)]
222-
(assoc ctx ::offsets offsets))
223-
(catch Exception e
224-
;; Don't fail the pipeline if offsets can't be captured, just log it
225-
;; This allows non-Emacs workflows to continue
226-
(log/error e "Warning: Failed to capture edit offsets -" (.getMessage e))
227-
ctx)))
228-
229192
(defn validate-form-type
230193
"Validates that the form type is supported for the operation.
231194
Returns the context unchanged if valid, or error context if invalid.
@@ -376,25 +339,6 @@
376339
(str "Changes made, but diff generation failed: " (.getMessage e)))))]
377340
(assoc ctx ::diff diff)))
378341

379-
#_(defn emacs-set-auto-revert
380-
"Ensures that the file is open in Emacs with auto-revert-mode enabled if notifications are enabled.
381-
Requires ::file-path and ::config in the context."
382-
[ctx]
383-
(try
384-
(let [file-path (::file-path ctx)
385-
config (::config ctx)]
386-
;; Only notify if emacs notifications are enabled in config
387-
(if (emacs/config-enables-emacs-notifications? config)
388-
(do
389-
(emacs/ensure-auto-revert file-path) ;; Now ensure-auto-revert is always async
390-
ctx)
391-
;; Otherwise return context unchanged
392-
ctx))
393-
;; Fail silently if emacs isn't started
394-
(catch Exception _
395-
;; Return context unchanged if Emacs integration fails
396-
ctx)))
397-
398342
(defn save-file
399343
"Saves the updated source to the file, creating parent directories if needed.
400344
Requires ::output-source and ::file-path in the context.
@@ -430,22 +374,6 @@
430374
(file-timestamps/update-file-timestamp-to-current-mtime! nrepl-client-atom file-path))
431375
ctx))
432376

433-
(defn highlight-form
434-
"Highlights the edited form in Emacs if notifications are enabled.
435-
Requires ::file-path, ::offsets, and ::config in the context."
436-
[ctx]
437-
(try
438-
(let [[start end] (::offsets ctx)
439-
config (::config ctx)]
440-
;; Only notify if emacs notifications are enabled in config
441-
(when (emacs/config-enables-emacs-notifications? config)
442-
(emacs/highlight-region (::file-path ctx) start end 2.0))
443-
ctx)
444-
;; Fail silently to support non-emacs workflow
445-
(catch Exception _
446-
;; Return context unchanged if highlighting fails
447-
ctx)))
448-
449377
;; Format result for tool consumption
450378
(defn format-result
451379
"Format the result of the pipeline for tool consumption.
@@ -504,15 +432,13 @@
504432
ctx
505433
lint-repair-code
506434
validate-form-type
507-
emacs-buffer-modified-check
508435
load-source
509436
file-changes/capture-original-file-content
510437
check-file-modified
511438
enhance-defmethod-name
512439
parse-source
513440
find-form
514441
edit-form
515-
capture-edit-offsets
516442
zloc->output-source
517443
format-source
518444
determine-file-type
@@ -522,21 +448,7 @@
522448
ctx
523449
(-> ctx
524450
save-file
525-
update-file-timestamp
526-
highlight-form))))))
527-
528-
(defn edit-locations->offsets [ctx]
529-
(try
530-
(let [zloc (::zloc ctx)
531-
positions (last (::edit-locations ctx))
532-
output-source (or (::output-source ctx) (z/root-string zloc))
533-
offsets (core/zloc-offsets output-source positions)]
534-
(assoc ctx ::offsets offsets))
535-
(catch Exception e
536-
;; Don't fail the pipeline if offsets can't be captured, just log it
537-
;; This allows non-Emacs workflows to continue
538-
(log/error e (str "Warning: Failed to capture edit offsets -" (ex-message e)))
539-
ctx)))
451+
update-file-timestamp))))))
540452

541453
(defn edit-sexp
542454
[{:keys [::zloc ::match-form ::new-form ::operation ::replace-all ::whitespace-sensitive] :as ctx}]
@@ -585,14 +497,12 @@
585497
ctx
586498
#(lint-repair-code % ::match-form)
587499
#(lint-repair-code % ::new-form)
588-
emacs-buffer-modified-check
589500
load-source
590501
file-changes/capture-original-file-content
591502
check-file-modified
592503
parse-source
593504
edit-sexp
594505
zloc->output-source
595-
edit-locations->offsets
596506
format-source
597507
determine-file-type
598508
generate-diff
@@ -601,8 +511,7 @@
601511
ctx
602512
(-> ctx
603513
save-file
604-
update-file-timestamp
605-
highlight-form))))))
514+
update-file-timestamp))))))
606515

607516
(comment
608517
;; Example usage of the pipelines
@@ -613,4 +522,4 @@
613522
"(defn example-fn [x y]\n (* x y))"
614523
:after
615524
nil
616-
{:enable-emacs-notifications true})))
525+
{})))

0 commit comments

Comments
 (0)