|
|
- ;;; functions.el --- A collection of my helper functions
- ;;
- ;;; Commentary:
- ;;
- ;;; Code:
-
- (defun leo/edit-config ()
- "Open ~/.doom.d/config.el."
- (interactive)
- (find-file "~/.doom.d/config.el"))
-
- (defun leo/tidy ()
- "Indent, untabify and unwhitespacify current buffer, or region if active."
- (interactive)
- (let ((beg (if (region-active-p) (region-beginning) (point-min)))
- (end (if (region-active-p) (region-end) (point-max))))
- (let ((inhibit-message t))
- (indent-region beg end))
- (whitespace-cleanup)
- (untabify beg (if (< end (point-max)) end (point-max)))
- (if (region-active-p) (message "Indenting Region...Done") (message "Indenting File...Done"))))
-
- (defun leo/comment-or-uncomment-region-or-line ()
- "Comment or uncomment the region or the current line if there's no active region."
- (interactive)
- (let (beg end)
- (if (region-active-p)
- (setq beg (region-beginning) end (region-end))
- (setq beg (line-beginning-position) end (line-end-position)))
- (comment-or-uncomment-region beg end)))
-
- (defun leo/duplicate-thing (comment)
- "Duplicates the current line, or the region if active. If an argument (COMMENT) is given, the duplicated region will be commented out."
- (interactive "P")
- (save-excursion
- (let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
- (end (if (region-active-p) (region-end) (point-at-eol))))
- (goto-char end)
- (unless (region-active-p)
- (newline))
- (insert (buffer-substring start end))
- (when comment (comment-region start end)))))
-
- (defun leo/kill-this-buffer-unless-scratch ()
- "Works like `kill-this-buffer' unless the current buffer is the *scratch* buffer. In which case the buffer content is deleted and the buffer is buried."
- (interactive)
- (if (or (string= (buffer-name) "*dashboard*") (string= (buffer-name) "*scratch*"))
- (progn
- (bury-buffer (buffer-name))
- (switch-to-buffer (other-buffer)))
- (kill-this-buffer)))
-
- (defun leo/jump-to-symbol (&optional backwardp)
- "Jumps to the next symbol near the point if such a symbol exists. If BACKWARDP is non-nil it jumps backward."
- (let* ((point (point))
- (bounds (find-tag-default-bounds))
- (beg (car bounds)) (end (cdr bounds))
- (str (isearch-symbol-regexp (find-tag-default)))
- (search (if backwardp 'search-backward-regexp
- 'search-forward-regexp)))
- (goto-char (if backwardp beg end))
- (funcall search str nil t)
- (cond ((<= beg (point) end) (goto-char point))
- (backwardp (forward-char (- point beg)))
- (t (backward-char (- end point))))))
-
- (defun leo/jump-to-prev-symbol ()
- "Jumps to the previous occurrence of the symbol at point."
- (interactive)
- (leo/jump-to-symbol t))
-
- (defun leo/jump-to-next-symbol ()
- "Jumps to the next occurrence of the symbol at point."
- (interactive)
- (leo/jump-to-symbol))
-
- (provide 'functions)
- ;;; functions.el ends here
|