|
|
- ;;; custom-functions --- custom functions prefixed with "leo/"
-
- ;;; Commentary:
-
- ;;; Code:
-
- (defun leo/compile-init ()
- "If the current buffer is 'init.el', compile it."
- (interactive)
- (when (equal (buffer-file-name)
- (expand-file-name (concat user-emacs-directory "init.el")))
- ;; Avoid running hooks when tangling.
- (let ((prog-mode-hook nil))
- (byte-compile-file (concat user-emacs-directory "init.el")))))
-
- (defun leo/find-user-init-file ()
- "Edit the `~/.emacs.d/init.el' file."
- (interactive)
- (find-file "~/.emacs.d/init.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))
-
- (defun leo/last-car (list)
- "Return only the item in the last position of a list."
- (car (last list))
- )
- (defun leo/get-package-from-url (url)
- "Accept a URL and return a stripped package name."
- (let ((mode
- (car
- (split-string
- (leo/last-car (split-string url "/" t))
- "\\." nil)
- )
- ))
- (message mode))
- )
-
-
- (provide 'custom-functions)
- ;;; custom-functions.el ends here
|