2023-02-04 18:04:14 +00:00
|
|
|
;;; xe-tools --- Xe's tools
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
2023-01-23 16:30:18 +00:00
|
|
|
(defun xe/count-buffers (&optional display-anyway)
|
|
|
|
"Display or return the number of buffers."
|
|
|
|
(interactive)
|
|
|
|
(let ((buf-count (length (buffer-list))))
|
|
|
|
(if (or (interactive-p) display-anyway)
|
|
|
|
(message "%d buffers in this Emacs" buf-count)) buf-count))
|
|
|
|
|
2023-01-23 17:56:41 +00:00
|
|
|
(defun xe/look-of-disapproval ()
|
2023-02-04 18:04:14 +00:00
|
|
|
"Just in case we need this."
|
2023-01-23 17:56:41 +00:00
|
|
|
(interactive)
|
|
|
|
(insert "ಠ_ಠ"))
|
|
|
|
|
2023-01-25 15:39:58 +00:00
|
|
|
(defun xe/enable-minor-mode (my-pair)
|
2023-02-04 18:04:14 +00:00
|
|
|
"Enable minor mode if filename match the regexp. MY-PAIR is a cons
|
|
|
|
cell (regexp . minor-mode)."
|
2023-01-25 15:39:58 +00:00
|
|
|
(if (buffer-file-name)
|
|
|
|
(if (string-match (car my-pair) buffer-file-name)
|
|
|
|
(funcall (cdr my-pair)))))
|
|
|
|
|
2023-02-04 18:04:14 +00:00
|
|
|
(defun xe/tabnew-shell ()
|
|
|
|
"Opens a shell in a new tab (tmux Control-b c)."
|
2023-02-04 18:12:58 +00:00
|
|
|
(interactive)
|
2023-02-04 18:04:14 +00:00
|
|
|
(tab-bar-new-tab 1)
|
2023-02-04 18:50:35 +00:00
|
|
|
(let ((proj-type (projectile-project-type)))
|
|
|
|
(if (eq proj-type 'nil)
|
|
|
|
(vterm)
|
|
|
|
(projectile-run-vterm)))
|
2023-02-04 18:04:14 +00:00
|
|
|
(rename-uniquely))
|
|
|
|
|
2023-02-22 02:51:38 +00:00
|
|
|
(defun xe/kill-whitespace ()
|
|
|
|
"Kill the whitespace between two non-whitespace characters"
|
|
|
|
(interactive "*")
|
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(save-match-data
|
|
|
|
(progn
|
|
|
|
(re-search-backward "[^ \t\r\n]" nil t)
|
|
|
|
(re-search-forward "[ \t\r\n]+" nil t)
|
|
|
|
(replace-match "" nil nil))))))
|
|
|
|
|
|
|
|
(defun xe/how-many-region (begin end regexp &optional interactive)
|
|
|
|
"Print number of non-trivial matches for REGEXP in region.
|
|
|
|
Non-interactive arguments are Begin End Regexp"
|
|
|
|
(interactive "r\nsHow many matches for (regexp): \np")
|
|
|
|
(let ((count 0) opoint)
|
|
|
|
(save-excursion
|
|
|
|
(setq end (or end (point-max)))
|
|
|
|
(goto-char (or begin (point)))
|
|
|
|
(while (and (< (setq opoint (point)) end)
|
|
|
|
(re-search-forward regexp end t))
|
|
|
|
(if (= opoint (point))
|
|
|
|
(forward-char 1)
|
|
|
|
(setq count (1+ count))))
|
|
|
|
(if interactive (message "%d occurrences" count))
|
|
|
|
count)))
|
|
|
|
|
|
|
|
(defun xe/linum-format-func (line)
|
|
|
|
"Properly format the line number"
|
|
|
|
(let ((w (length (number-to-string (count-lines (point-min) (point-max))))))
|
|
|
|
(propertize (format (format " %%%dd " w) line) 'face 'linum)))
|
|
|
|
|
2023-01-23 16:30:18 +00:00
|
|
|
(provide 'xe-tools)
|
2023-02-04 18:04:14 +00:00
|
|
|
;;; xe-tools.el ends here
|