<commit_before>;;; lang/emacs-lisp/autoload.el -*- lexical-binding: t; -*-

;;
;; Library

;;;###autoload
(defun +emacs-lisp-eval (beg end)
  "Evaluate a region and print it to the echo area (if one line long), otherwise
to a pop up buffer."
  (require 'pp)
  (let ((result (eval (read (concat "(progn " (buffer-substring-no-properties beg end) "\n)"))))
        (buf (get-buffer-create "*doom eval*"))
        (inhibit-read-only t)
        lines)
    (with-current-buffer buf
      (read-only-mode +1)
      (erase-buffer)
      (setq-local scroll-margin 0)
      (let (emacs-lisp-mode-hook)
        (emacs-lisp-mode))
      (prin1 result buf)
      (pp-buffer)
      (setq lines (count-lines (point-min) (point-max)))
      (cond ((> lines 1)
             (save-selected-window
               (pop-to-buffer buf)
               (with-current-buffer buf
                 (goto-char (point-min)))))
            (t
             (message "%s" (buffer-substring (point-min) (point-max)))
             (kill-buffer buf))))))

(defvar +emacs-lisp--face nil)
;;;###autoload
(defun +emacs-lisp-highlight-vars-and-faces (end)
  "Match defined variables and functions.

Functions are differentiated into special forms, built-in functions and
library/userland functions"
  (catch 'matcher
    (while (re-search-forward "\\_<.+?\\_>" end t)
      (unless (save-excursion
                (let ((ppss (syntax-ppss)))
                  (or (nth 3 ppss) (nth 4 ppss))))
        (let ((symbol (intern-soft (match-string-no-properties 0))))
          (and (cond ((null symbol) nil)
                     ((eq symbol t) nil)
                     ((special-variable-p symbol)
                      (setq +emacs-lisp--face 'font-lock-variable-name-face))
                     ((and (fboundp symbol)
                           (eq (char-before (match-beginning 0)) ?\())
                      (let ((unaliased (indirect-function symbol)))
                        (unless (or (macrop unaliased)
                                    (special-form-p unaliased))
                          (let (unadvised)
                            (while (not (eq (setq unadvised (ad-get-orig-definition unaliased))
                                            (setq unaliased (indirect-function unadvised)))))
                            unaliased)
                          (setq +emacs-lisp--face
                                (if (subrp unaliased)
                                    'font-lock-constant-face
                                  'font-lock-function-name-face))))))
               (throw 'matcher t)))))
    nil))

;; `+emacs-lisp-highlight-vars-and-faces' is a potentially expensive function
;; and should be byte-compiled, no matter what, to ensure it runs as fast as
;; possible:
(eval-when-compile
  (with-no-warnings
    (byte-compile #'+emacs-lisp-highlight-vars-and-faces)))


;;
;; Commands

;;;###autoload
(defun +emacs-lisp/repl ()
  "Open the Emacs Lisp REPL (`ielm')."
  (interactive)
  (pop-to-buffer
   (or (get-buffer "*ielm*")
       (progn (ielm)
              (let ((buf (get-buffer "*ielm*")))
                (bury-buffer buf)
                buf)))))


;;
;; Hooks

;;;###autoload
(defun +emacs-lisp|extend-imenu ()
  "Improve imenu support with better expression regexps and Doom-specific forms."
  (setq imenu-generic-expression
        '(("Evil Commands" "^\\s-*(evil-define-\\(?:command\\|operator\\|motion\\) +\\(\\_<[^ ()\n]+\\_>\\)" 1)
          ("Unit tests" "^\\s-*(\\(?:ert-deftest\\|describe\\) +\"\\([^\")]+\\)\"" 1)
          ("Package" "^\\s-*(\\(?:def-\\)?package! +\\(\\_<[^ ()\n]+\\_>\\)" 1)
          ("Settings" "^\\s-*(def-setting! +\\([^ ()\n]+\\)" 1)
          ("Major modes" "^\\s-*(define-derived-mode +\\([^ ()\n]+\\)" 1)<commit_msg>make compile: fix error in emacs-lisp<commit_after>;;; lang/emacs-lisp/autoload.el -*- lexical-binding: t; -*-

;;
;; Library

;;;###autoload
(defun +emacs-lisp-eval (beg end)
  "Evaluate a region and print it to the echo area (if one line long), otherwise
to a pop up buffer."
  (require 'pp)
  (let ((result (eval (read (concat "(progn " (buffer-substring-no-properties beg end) "\n)"))))
        (buf (get-buffer-create "*doom eval*"))
        (inhibit-read-only t)
        lines)
    (with-current-buffer buf
      (read-only-mode +1)
      (erase-buffer)
      (setq-local scroll-margin 0)
      (let (emacs-lisp-mode-hook)
        (emacs-lisp-mode))
      (prin1 result buf)
      (pp-buffer)
      (setq lines (count-lines (point-min) (point-max)))
      (cond ((> lines 1)
             (save-selected-window
               (pop-to-buffer buf)
               (with-current-buffer buf
                 (goto-char (point-min)))))
            (t
             (message "%s" (buffer-substring (point-min) (point-max)))
             (kill-buffer buf))))))

(defvar +emacs-lisp--face nil)
;;;###autoload
(defun +emacs-lisp-highlight-vars-and-faces (end)
  "Match defined variables and functions.

Functions are differentiated into special forms, built-in functions and
library/userland functions"
  (catch 'matcher
    (while (re-search-forward "\\_<.+?\\_>" end t)
      (unless (save-excursion
                (let ((ppss (syntax-ppss)))
                  (or (nth 3 ppss) (nth 4 ppss))))
        (let ((symbol (intern-soft (match-string-no-properties 0))))
          (and (cond ((null symbol) nil)
                     ((eq symbol t) nil)
                     ((special-variable-p symbol)
                      (setq +emacs-lisp--face 'font-lock-variable-name-face))
                     ((and (fboundp symbol)
                           (eq (char-before (match-beginning 0)) ?\())
                      (let ((unaliased (indirect-function symbol)))
                        (unless (or (macrop unaliased)
                                    (special-form-p unaliased))
                          (let (unadvised)
                            (while (not (eq (setq unadvised (ad-get-orig-definition unaliased))
                                            (setq unaliased (indirect-function unadvised)))))
                            unaliased)
                          (setq +emacs-lisp--face
                                (if (subrp unaliased)
                                    'font-lock-constant-face
                                  'font-lock-function-name-face))))))
               (throw 'matcher t)))))
    nil))

;; `+emacs-lisp-highlight-vars-and-faces' is a potentially expensive function
;; and should be byte-compiled, no matter what, to ensure it runs as fast as
;; possible:
(when (not (byte-code-function-p (symbol-function '+emacs-lisp-highlight-vars-and-faces)))
  (with-no-warnings
    (byte-compile #'+emacs-lisp-highlight-vars-and-faces)))


;;
;; Commands

;;;###autoload
(defun +emacs-lisp/repl ()
  "Open the Emacs Lisp REPL (`ielm')."
  (interactive)
  (pop-to-buffer
   (or (get-buffer "*ielm*")
       (progn (ielm)
              (let ((buf (get-buffer "*ielm*")))
                (bury-buffer buf)
                buf)))))


;;
;; Hooks

;;;###autoload
(defun +emacs-lisp|extend-imenu ()
  "Improve imenu support with better expression regexps and Doom-specific forms."
  (setq imenu-generic-expression
        '(("Evil Commands" "^\\s-*(evil-define-\\(?:command\\|operator\\|motion\\) +\\(\\_<[^ ()\n]+\\_>\\)" 1)
          ("Unit tests" "^\\s-*(\\(?:ert-deftest\\|describe\\) +\"\\([^\")]+\\)\"" 1)
          ("Package" "^\\s-*(\\(?:def-\\)?package! +\\(\\_<[^ ()\n]+\\_>\\)" 1)
          ("Settings" "^\\s-*(def-setting! +\\([^ ()\n]+\\)" 1)
          ("Major modes" "^\\s-*(define-derived-mode +\\([^ ()\n]+\\)" 1)
{'fraction_non_alphanumeric': 0.1788906414300736, 'fraction_numerical': 0.0034174553101997897, 'mean_word_length': 1.7892228739002933, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7570785', 'n_tokens_mistral': 2524, 'n_tokens_neox': 2418, 'n_words': 560}