<commit_before>(setenv "PAGER" "cat")

(require 'dirtrack)
(setq-default dirtrack-list (list "^\\([^(]+\\)\\( .*?\\)?[$] $" 1))
;;
;; (let ((possibles '("/$ " "~$ " "~/my/test (master)$ "))
;;       (results '()))
;;   (dolist (p possibles)
;;     (push (cons p
;;                 (and (string-match (car dirtrack-list) p)
;;                      (match-string (cadr dirtrack-list) p)))
;;           results))
;;   results)

(defun my-setup-shell-header-line ()
  (setq header-line-format
        (list (propertize " [↩]"
                          'mouse-face 'mode-line-highlight
                          'help-echo "erase buffer"
                          'local-map (my-make-header-line-mouse-map
                                      'down-mouse-1 #'ignore
                                      'mouse-1 #'my-header-line-shell-erase-buffer))
              (propertize " [↩!]"
                          'mouse-face 'mode-line-highlight
                          'help-echo "erase buffer & run prev cmd"
                          'local-map (my-make-header-line-mouse-map
                                      'down-mouse-1 #'ignore
                                      'mouse-1 #'my-header-line-shell-erase-buffer-and-run-prev-cmd)))))

(defun my-shell-forward-char-or-previous-history (&optional arg)
  (interactive "p")
  (if (eobp)
      (comint-previous-input arg)
    (forward-char arg)))

(defun my-shell-next-line-or-next-history (&optional arg)
  (interactive "p")
  (if (eobp)
      (comint-next-input arg)
    (next-line arg)))

(defun my-shell-erase-buffer ()
  (interactive)
  (erase-buffer)
  (comint-send-input))

;; If there is a visible "rspec" (*_spec.rb) buffer in the
;; current frame, running a "rspec" command is a shell process,
;; will run rspec against that buffer's file name (at the line
;; where the cursor is in that buffer). Add this to your shell-mode-hook
;; to enable this feature:
;;     (add-hook 'shell-mode-hook
;;               (lambda ()
;;                 (setq comint-input-sender 'my-shell-rspec-command)))
;;
(defun my-shell-rspec-command (proc string)
  (when (string-match "^rspec\n?$" string)
    (let ((buffers (mapcar #'window-buffer (window-list)))
          (spec-buffer nil))
      (dolist (buf buffers)
        (when (string-match "_(spec|test)[.]rb$" (or (buffer-file-name buf) ""))
          (setq spec-buffer buf)))
      (when spec-buffer
        (let ((n (with-current-buffer spec-buffer
                   (line-number-at-pos))))
          (setq string (format "rspec %s:%d"
                               (buffer-file-name spec-buffer)
                               n))
          (message "Running \"%s\"" string)))))
  (comint-simple-send proc string))

(defun my-shell-input-sender (proc string)
  (catch 'dont-proceed
    (cond ((string-match "^eo \\(.*\\)$" string)
           (find-file-other-window (match-string 1 string))
           (throw 'dont-proceed t)))
    (comint-simple-send proc string)))

(add-hook 'shell-mode-hook
          (lambda ()
            (my-setup-shell-header-line)
            (linum-mode -1)
            (setq line-number-mode nil
                  column-number-mode nil)
            (setq comint-input-sender
                  'my-shell-input-sender)
            (toggle-truncate-lines 1)<commit_msg>eo -- open file from shell (running under emacs) in emacs buffer<commit_after>(setenv "PAGER" "cat")

(require 'dirtrack)
(setq-default dirtrack-list (list "^\\([^(]+\\)\\( .*?\\)?[$] $" 1))
;;
;; (let ((possibles '("/$ " "~$ " "~/my/test (master)$ "))
;;       (results '()))
;;   (dolist (p possibles)
;;     (push (cons p
;;                 (and (string-match (car dirtrack-list) p)
;;                      (match-string (cadr dirtrack-list) p)))
;;           results))
;;   results)

(defun my-setup-shell-header-line ()
  (setq header-line-format
        (list (propertize " [↩]"
                          'mouse-face 'mode-line-highlight
                          'help-echo "erase buffer"
                          'local-map (my-make-header-line-mouse-map
                                      'down-mouse-1 #'ignore
                                      'mouse-1 #'my-header-line-shell-erase-buffer))
              (propertize " [↩!]"
                          'mouse-face 'mode-line-highlight
                          'help-echo "erase buffer & run prev cmd"
                          'local-map (my-make-header-line-mouse-map
                                      'down-mouse-1 #'ignore
                                      'mouse-1 #'my-header-line-shell-erase-buffer-and-run-prev-cmd)))))

(defun my-shell-forward-char-or-previous-history (&optional arg)
  (interactive "p")
  (if (eobp)
      (comint-previous-input arg)
    (forward-char arg)))

(defun my-shell-next-line-or-next-history (&optional arg)
  (interactive "p")
  (if (eobp)
      (comint-next-input arg)
    (next-line arg)))

(defun my-shell-erase-buffer ()
  (interactive)
  (erase-buffer)
  (comint-send-input))

;; If there is a visible "rspec" (*_spec.rb) buffer in the
;; current frame, running a "rspec" command is a shell process,
;; will run rspec against that buffer's file name (at the line
;; where the cursor is in that buffer). Add this to your shell-mode-hook
;; to enable this feature:
;;     (add-hook 'shell-mode-hook
;;               (lambda ()
;;                 (setq comint-input-sender 'my-shell-rspec-command)))
;;
(defun my-shell-rspec-command (proc string)
  (when (string-match "^rspec\n?$" string)
    (let ((buffers (mapcar #'window-buffer (window-list)))
          (spec-buffer nil))
      (dolist (buf buffers)
        (when (string-match "_(spec|test)[.]rb$" (or (buffer-file-name buf) ""))
          (setq spec-buffer buf)))
      (when spec-buffer
        (let ((n (with-current-buffer spec-buffer
                   (line-number-at-pos))))
          (setq string (format "rspec %s:%d"
                               (buffer-file-name spec-buffer)
                               n))
          (message "Running \"%s\"" string)))))
  (comint-simple-send proc string))

(defun my-shell-input-sender (proc string)
  (let ((curbuf (current-buffer)))
    (cond ((string-match "^eo \\(.*\\)$" string)
           (let ((path (match-string 1 string)))
             (when (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'" path)
               (setq path (replace-match "" t t path)))
             (find-file-other-window path)
             (set-buffer curbuf)
             (setq string ""))))
    (comint-simple-send proc string)))

(add-hook 'shell-mode-hook
          (lambda ()
            (my-setup-shell-header-line)
            (linum-mode -1)
            (setq line-number-mode nil
                  column-number-mode nil)
            (setq comint-input-sender
                  'my-shell-input-sender)
            (toggle-truncate-lines 1)
{'fraction_non_alphanumeric': 0.1627499635089768, 'fraction_numerical': 0.0023354254853306085, 'mean_word_length': 1.7440929114937926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2181505', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2151, 'n_words': 488}