Create a function to open codesearch #28

Open
opened 2026-04-06 12:51:20 -07:00 by wmedrano · 0 comments
Owner

Create a function to open codesearch

LLM Generated:

(defun my/chromium-code-search-current-file ()
  "Open the current file in Chromium Code Search.
Automatically appends the current line number to the URL."
  (interactive)
  (let ((filepath (buffer-file-name)))
    (unless filepath
      (user-error "Current buffer is not visiting a file"))
    
    (let* ((expanded-path (expand-file-name filepath))
           ;; Locate the root of the repository (usually the 'src' directory)
           (root-dir (expand-file-name (or (vc-root-dir)
                                           (locate-dominating-file expanded-path ".git")
                                           (user-error "Could not determine project root"))))
           ;; Get the path relative to the project root
           (relative-path (file-relative-name expanded-path root-dir))
           ;; Get current line number
           (line-num (line-number-at-pos))
           ;; Construct the URL
           (base-url "https://source.chromium.org/chromium/chromium/src/+/main:")
           (full-url (format "%s%s;l=%d" base-url relative-path line-num)))
      
      ;; Open the URL in the default browser
      (browse-url full-url)
      (message "Opening: %s" full-url))))
Create a function to open codesearch LLM Generated: ```lisp (defun my/chromium-code-search-current-file () "Open the current file in Chromium Code Search. Automatically appends the current line number to the URL." (interactive) (let ((filepath (buffer-file-name))) (unless filepath (user-error "Current buffer is not visiting a file")) (let* ((expanded-path (expand-file-name filepath)) ;; Locate the root of the repository (usually the 'src' directory) (root-dir (expand-file-name (or (vc-root-dir) (locate-dominating-file expanded-path ".git") (user-error "Could not determine project root")))) ;; Get the path relative to the project root (relative-path (file-relative-name expanded-path root-dir)) ;; Get current line number (line-num (line-number-at-pos)) ;; Construct the URL (base-url "https://source.chromium.org/chromium/chromium/src/+/main:") (full-url (format "%s%s;l=%d" base-url relative-path line-num))) ;; Open the URL in the default browser (browse-url full-url) (message "Opening: %s" full-url)))) ```
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
wmedrano/emacs-config#28
No description provided.