I am using Common Lisp, SBCL, Emacs, and Slime. During a code review, a co-worker mentioned that the indentation of an s-expression was wrong.
Usually, I just use indent-sexp
(bounded to C-M-q
) to fix this kind of situation. In this case, I forgot to use it before code review. After his comment, I just executed the command.
This was the previous code:
(defun bookmark-frequent-visit (threshold)"Check if current URL is frequently visited and not included in thebookmarks. If this is the case, prompt the user about bookmarking it." (labels ((bookmarked-url-p (url-address)"The local function `bookmarked-url-p' returns the URL address itself if it is new to the bookmark list or NIL if it is already there." (let ((bookmarks-address-list (mapcar #'(lambda (e) (render-url (url e))) (with-data-unsafe (bookmarks (bookmarks-path (current-buffer))) bookmarks)))) (if (member url-address bookmarks-address-list :test #'string=) nil url-address)))) (sera:and-let* ((history-entries (with-data-unsafe (history (history-path (current-buffer))) (mapcar #'htree:data (alex:hash-table-keys (htree:entries history))))) (current-url-history (find (url (current-buffer)) history-entries :test #'equalp :key #'url)) (implicit-visits-value (nyxt::implicit-visits current-url-history)) (current-url-address (render-url (url current-url-history))) (threshold threshold)) (run-thread ;; identation is off here (if (and (> implicit-visits-value threshold) (bookmarked-url-p current-url-address)) (if-confirm ("Bookmark ~a?" current-url-address) (bookmark-url :url current-url-address)))))))
This is the new code with my attempt to fix it:
(defun bookmark-frequent-visit (threshold)"Check if current URL is frequently visited and not included in thebookmarks. If this is the case, prompt the user about bookmarking it." (labels ((bookmarked-url-p (url-address)"The local function `bookmarked-url-p' returns the URL address itself if it is new to the bookmark list or NIL if it is already there." (let ((bookmark-url-strings (mapcar #'(lambda (e) (render-url (url e))) (with-data-unsafe (bookmarks (bookmarks-path (current-buffer))) bookmarks)))) (if (member url-address bookmark-url-strings :test #'string=) nil url-address)))) (sera:and-let* ((history-entries (with-data-unsafe (history (history-path (current-buffer))) (mapcar #'htree:data (alex:hash-table-keys (htree:entries history))))) (current-url-history (find (url (current-buffer)) history-entries :test #'equalp :key #'url)) (implicit-visits-value (nyxt::implicit-visits current-url-history)) (current-url-string (render-url (url current-url-history))) (threshold threshold)) (run-thread ;; attempt to fix the indentation with C-M-q (if (and (> implicit-visits-value threshold) (bookmarked-url-p current-url-string)) (if-confirm ("Bookmark ~a?" current-url-string) (bookmark-url :url current-url-string)))))))
One thing intrigued me, though. He said: "make sure the system is loaded".
Why having the system loaded makes any difference for indentation?