<commit_before>;;; defuns-buffers.el

;;;###autoload (autoload 'narf:narrow "defuns-buffers" nil t)
(evil-define-operator narf:narrow (&optional beg end bang)
  "Restrict editing in this buffer to the current region, indirectly. With BANG,
clone the buffer and hard-narrow the selection. Otherwise use fancy-narrow. If
mark isn't active, then widen the buffer (if narrowed).

Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
  (interactive "<r><!>")
  (if (region-active-p)
      (progn
        (deactivate-mark)
        (let ((buf (clone-indirect-buffer nil nil)))
          (with-current-buffer buf
            (narrow-to-region start end))
          (switch-to-buffer buf)))
    (widen)))

;;;###autoload
(defun narf/set-read-only-region (begin end)
  "See http://stackoverflow.com/questions/7410125"
  (let ((modified (buffer-modified-p)))
    (add-text-properties begin end '(read-only t))
    (set-buffer-modified-p modified)))

;;;###autoload
(defun narf/set-region-writeable (begin end)
  "See http://stackoverflow.com/questions/7410125"
  (let ((modified (buffer-modified-p))
        (inhibit-read-only t))
    (remove-text-properties begin end '(read-only t))
    (set-buffer-modified-p modified)))


;; Buffer Life and Death ;;;;;;;;;;;;;;;

;;;###autoload
(defun narf/get-all-buffers ()
  "Get all buffers across all workgroups. Depends on
`wg-mess-with-buffer-list'."
  (if (and (featurep 'workgroups2) workgroups-mode wg-mess-with-buffer-list)
      (wg-buffer-list-emacs)
    (buffer-list)))

;;;###autoload
(defun narf/get-buffers ()
  "Get all buffers in the current workgroup. Depends on
`wg-mess-with-buffer-list'."
  (wg-workgroup-associated-buffers (wg-current-workgroup)))

;;;###autoload
(defun narf/get-visible-windows ()
  (-map #'get-buffer-window (narf/get-visible-buffers (narf/get-all-buffers))))

;;;###autoload
(defun narf/get-visible-buffers (&optional buffer-list)
  "Get a list of buffers that are not buried (i.e. visible)"
  (-filter #'get-buffer-window (or buffer-list (narf/get-all-buffers))))

;;;###autoload
(defun narf/get-buried-buffers (&optional buffer-list)
  "Get a list of buffers that are buried (i.e. not visible)"
  (let* ((buffers (or buffer-list (narf/get-buffers)))
         (old-len (length buffers)))
    (-remove 'get-buffer-window buffers)))

;;;###autoload
(defun narf/get-matching-buffers (pattern &optional buffer-list)
  "Get a list of buffers that match the pattern"
  (--filter (string-match-p pattern (buffer-name it))
            (or buffer-list (narf/get-buffers))))

;;;###autoload
(defun narf/get-real-buffers (&optional buffer-list)
  (-filter #'narf/real-buffer-p (or buffer-list (narf/get-buffers))))

;;;###autoload
(defun narf:kill-real-buffer ()
  "Kill buffer (but only bury scratch buffer), then switch to a real buffer."
  (interactive)
  (let ((bname (buffer-name)))
    (cond ((string-match-p "^\\*scratch\\*" bname)
           (erase-buffer))
          (t (kill-this-buffer))))
  (if (narf/popup-p (current-buffer))<commit_msg>Bury other windows in narf/kill-real-buffer<commit_after>;;; defuns-buffers.el

;;;###autoload (autoload 'narf:narrow "defuns-buffers" nil t)
(evil-define-operator narf:narrow (&optional beg end bang)
  "Restrict editing in this buffer to the current region, indirectly. With BANG,
clone the buffer and hard-narrow the selection. Otherwise use fancy-narrow. If
mark isn't active, then widen the buffer (if narrowed).

Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
  (interactive "<r><!>")
  (if (region-active-p)
      (progn
        (deactivate-mark)
        (let ((buf (clone-indirect-buffer nil nil)))
          (with-current-buffer buf
            (narrow-to-region start end))
          (switch-to-buffer buf)))
    (widen)))

;;;###autoload
(defun narf/set-read-only-region (begin end)
  "See http://stackoverflow.com/questions/7410125"
  (let ((modified (buffer-modified-p)))
    (add-text-properties begin end '(read-only t))
    (set-buffer-modified-p modified)))

;;;###autoload
(defun narf/set-region-writeable (begin end)
  "See http://stackoverflow.com/questions/7410125"
  (let ((modified (buffer-modified-p))
        (inhibit-read-only t))
    (remove-text-properties begin end '(read-only t))
    (set-buffer-modified-p modified)))


;; Buffer Life and Death ;;;;;;;;;;;;;;;

;;;###autoload
(defun narf/get-all-buffers ()
  "Get all buffers across all workgroups. Depends on
`wg-mess-with-buffer-list'."
  (if (and (featurep 'workgroups2) workgroups-mode wg-mess-with-buffer-list)
      (wg-buffer-list-emacs)
    (buffer-list)))

;;;###autoload
(defun narf/get-buffers ()
  "Get all buffers in the current workgroup. Depends on
`wg-mess-with-buffer-list'."
  (wg-workgroup-associated-buffers (wg-current-workgroup)))

;;;###autoload
(defun narf/get-visible-windows ()
  (-map #'get-buffer-window (narf/get-visible-buffers (narf/get-all-buffers))))

;;;###autoload
(defun narf/get-visible-buffers (&optional buffer-list)
  "Get a list of buffers that are not buried (i.e. visible)"
  (-filter #'get-buffer-window (or buffer-list (narf/get-all-buffers))))

;;;###autoload
(defun narf/get-buried-buffers (&optional buffer-list)
  "Get a list of buffers that are buried (i.e. not visible)"
  (let* ((buffers (or buffer-list (narf/get-buffers)))
         (old-len (length buffers)))
    (-remove 'get-buffer-window buffers)))

;;;###autoload
(defun narf/get-matching-buffers (pattern &optional buffer-list)
  "Get a list of buffers that match the pattern"
  (--filter (string-match-p pattern (buffer-name it))
            (or buffer-list (narf/get-buffers))))

;;;###autoload
(defun narf/get-real-buffers (&optional buffer-list)
  (-filter #'narf/real-buffer-p (or buffer-list (narf/get-buffers))))

;;;###autoload
(defun narf:kill-real-buffer ()
  "Kill buffer (but only bury scratch buffer), then switch to a real buffer."
  (interactive)
  (let ((bname (buffer-name)))
    (cond ((string-match-p "^\\*scratch\\*" bname)
           (erase-buffer))
          (t ;; bury duplicate buffers in other windows
           (let ((this-window (get-buffer-window)))
             (mapc (lambda (w)
                     (unless (eq this-window w)
                       (with-selected-window w (narf/previous-real-buffer))))
                   (get-buffer-window-list (current-buffer) nil nil)))
           ;; Then kill
           (kill-this-buffer))))
  (if (narf/popup-p (current-buffer))
{'fraction_non_alphanumeric': 0.16904466501240695, 'fraction_numerical': 0.006513647642679901, 'mean_word_length': 3.469161469161469, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7189804', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2199, 'n_words': 550}