From 97ebfa54bc63ce47d4f07f1c80796721730ce98f Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Tue, 23 Dec 2025 14:46:27 +0100 Subject: [PATCH] clean up Emacs http-status-code function Specifically, make the completing read show both status code and status phrase on the same line. This removes the need for "safe phrase" in the `http-status` constant since the description lookup always is done by the status code. --- generators/emacs/http-status-codes.el | 2 -- generators/emacs/http-status-codes.el.tpl | 14 +++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/generators/emacs/http-status-codes.el b/generators/emacs/http-status-codes.el index 7da62cd..bf8e938 100755 --- a/generators/emacs/http-status-codes.el +++ b/generators/emacs/http-status-codes.el @@ -11,7 +11,5 @@ extract '../master/status-codes.md', "^`([0-9a-zA-Z]{3})` \\\| ([^\\\|]+) \\\| ( continue unless parseInt(match[0]).toString() is match[0] match = (item.replace /\"/g, '' for item in match) matchesEl.push "(\"#{match[0]}\" (\"#{match[1]}\" \"#{match[2]}\"))" - safePhrase = match[1].toUpperCase().replace /[^A-Z]/g, '_' - matchesEl.push "(\"#{safePhrase}\" (\"#{match[0]}\" \"#{match[2]}\"))" matchesEl = matchesEl.join "\n" console.log tpl.replace '{{ HTTP_STATUS }}', matchesEl diff --git a/generators/emacs/http-status-codes.el.tpl b/generators/emacs/http-status-codes.el.tpl index 970212c..e55a448 100644 --- a/generators/emacs/http-status-codes.el.tpl +++ b/generators/emacs/http-status-codes.el.tpl @@ -34,13 +34,17 @@ (defconst http-status '({{ HTTP_STATUS }})) +(defun http-status-codes--prompt-for-code () + "Prompt the user for an HTTP status code and returns the chosen code." + (let* ((format-entry (lambda (entry) (format "%s %s" (car entry) (caadr entry)))) + (entries (mapcar format-entry http-status))) + (car (split-string (completing-read "HTTP status: " entries))))) + ;;;###autoload (defun http-status-code (status) "Display the meaning of an HTTP status code or phrase" - (interactive - (list (completing-read "Enter HTTP status code or phrase: " http-status))) - (let* ((uppercased-status (upcase status)) - (found (assoc uppercased-status http-status))) + (interactive (list (http-status-codes--prompt-for-code))) + (let ((found (assoc status http-status))) (if found (let* ((status-code (car found)) (status-code-attrib (cdr found)) @@ -49,7 +53,7 @@ (message "%s - HTTP status\n%s\n%s" status-code phrase description)) - (message "%s - HTTP status\nUNKNOWN" uppercased-status)) + (message "%s - HTTP status\nUNKNOWN" status)) )) (provide 'http-status-codes)