Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions generators/emacs/http-status-codes.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions generators/emacs/http-status-codes.el.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down