My attempt to optimize my emacs load time <1 second
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.6 KiB

  1. ;; -*- lexical-binding: t; -*-
  2. ;;; custom-functions --- custom functions prefixed with "leo/"
  3. (defun leo/compile-init ()
  4. "If the current buffer is 'init.el', compile it."
  5. (interactive)
  6. (when (equal (buffer-file-name)
  7. (expand-file-name (concat user-emacs-directory "init.el")))
  8. ;; Avoid running hooks when tangling.
  9. (let ((prog-mode-hook nil))
  10. (byte-compile-file (concat user-emacs-directory "init.el")))))
  11. (defun leo/find-user-init-file ()
  12. "Edit the `~/.emacs.d/init.el' file."
  13. (interactive)
  14. (find-file "~/.emacs.d/init.el"))
  15. (defun leo/tidy ()
  16. "Indent, untabify and unwhitespacify current buffer, or region if active."
  17. (interactive)
  18. (let ((beg (if (region-active-p) (region-beginning) (point-min)))
  19. (end (if (region-active-p) (region-end) (point-max))))
  20. (let ((inhibit-message t))
  21. (indent-region beg end))
  22. (whitespace-cleanup)
  23. (untabify beg (if (< end (point-max)) end (point-max)))
  24. (if (region-active-p) (message "Indenting Region...Done") (message "Indenting File...Done"))))
  25. (defun leo/comment-or-uncomment-region-or-line ()
  26. "Comment or uncomment the region or the current line if there's no active region."
  27. (interactive)
  28. (let (beg end)
  29. (if (region-active-p)
  30. (setq beg (region-beginning) end (region-end))
  31. (setq beg (line-beginning-position) end (line-end-position)))
  32. (comment-or-uncomment-region beg end)))
  33. (defun leo/duplicate-thing (comment)
  34. "Duplicates the current line, or the region if active. If an argument (COMMENT) is given, the duplicated region will be commented out."
  35. (interactive "P")
  36. (save-excursion
  37. (let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
  38. (end (if (region-active-p) (region-end) (point-at-eol))))
  39. (goto-char end)
  40. (unless (region-active-p)
  41. (newline))
  42. (insert (buffer-substring start end))
  43. (when comment (comment-region start end)))))
  44. (defun leo/kill-this-buffer-unless-scratch ()
  45. "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."
  46. (interactive)
  47. (if (or (string= (buffer-name) "*dashboard*") (string= (buffer-name) "*scratch*"))
  48. (progn
  49. (bury-buffer (buffer-name))
  50. (switch-to-buffer (other-buffer)))
  51. (kill-this-buffer)))
  52. (defun leo/jump-to-symbol (&optional backwardp)
  53. "Jumps to the next symbol near the point if such a symbol exists. If BACKWARDP is non-nil it jumps backward."
  54. (let* ((point (point))
  55. (bounds (find-tag-default-bounds))
  56. (beg (car bounds)) (end (cdr bounds))
  57. (str (isearch-symbol-regexp (find-tag-default)))
  58. (search (if backwardp 'search-backward-regexp
  59. 'search-forward-regexp)))
  60. (goto-char (if backwardp beg end))
  61. (funcall search str nil t)
  62. (cond ((<= beg (point) end) (goto-char point))
  63. (backwardp (forward-char (- point beg)))
  64. (t (backward-char (- end point))))))
  65. (defun leo/jump-to-prev-symbol ()
  66. "Jumps to the previous occurrence of the symbol at point."
  67. (interactive)
  68. (leo/jump-to-symbol t))
  69. (defun leo/jump-to-next-symbol ()
  70. "Jumps to the next occurrence of the symbol at point."
  71. (interactive)
  72. (leo/jump-to-symbol))
  73. (defun leo/last-car (list)
  74. "Return only the item in the last position of a list."
  75. (car (last list))
  76. )
  77. (defun leo/get-package-from-url (url)
  78. "Accept a URL and return a stripped package name."
  79. (let ((mode
  80. (car
  81. (split-string
  82. (leo/last-car (split-string url "/" t))
  83. "\\." nil)
  84. )
  85. ))
  86. (message mode))
  87. )
  88. (provide 'custom-functions)