diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2023-04-10 19:05:10 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2023-04-10 19:05:10 +0200 |
| commit | 97f354506f78e07e3df1f8c8b41b88db617e144b (patch) | |
| tree | f6d5ec399546ab47588e5a5a806461db10e1d666 | |
| parent | 5079a7e0f92260d5ef34014c9aceae356582027a (diff) | |
| -rw-r--r-- | emacs-blue | 226 |
1 files changed, 140 insertions, 86 deletions
@@ -12,7 +12,7 @@ '("melpa" . "https://melpa.org/packages/")) (package-initialize) (setq - package-selected-packages '(meson-mode groovy-mode gradle-mode flycheck ido-vertical-mode)) + package-selected-packages '(meson-mode groovy-mode gradle-mode kotlin-mode flycheck glsl-mode java-imports ido-vertical-mode rg)) ;; use (package-install-selected-packages) to install the ones above ;; show matching parentheses (and other characters) @@ -45,14 +45,35 @@ ;; Clean the buffer list at midnight (require 'midnight) -;; Set clean-buffer-list delay to 1 day -(setq clean-buffer-list-delay-general 1) +;; Set clean-buffer-list delay to 3 days +(setq clean-buffer-list-delay-general 3) (if (not (boundp 'clean-buffer-list-kill-regexps)) (setq clean-buffer-list-kill-regexps '())) ;; Add preprocessed buffers to the list (add-to-list 'clean-buffer-list-kill-regexps '("\\`\\*.*-preprocessed\\*\\'")) +(defun rename-current-buffer-file () + "Renames current buffer and file it is visiting." + (interactive) + (let* ((name (buffer-name)) + (filename (buffer-file-name)) + (basename (file-name-nondirectory filename))) + (if (not (and filename (file-exists-p filename))) + (error "Buffer '%s' is not visiting a file!" name) + (let ((new-name (read-file-name "New name: " (file-name-directory filename) basename nil basename))) + (if (get-buffer new-name) + (error "A buffer named '%s' already exists!" new-name) + (rename-file filename new-name 1) + (rename-buffer new-name) + (set-visited-file-name new-name) + (set-buffer-modified-p nil) + (message "File '%s' successfully renamed to '%s'" + name (file-name-nondirectory new-name))))))) + +;; load rg +(require 'rg) + (setq ;; create backups make-backup-files t @@ -78,7 +99,7 @@ (add-to-list 'default-frame-alist '(user-size . t)) ;; frame font and color (add-to-list 'default-frame-alist - '(font . "-*-inconsolata-*-*-*-*-*-120-*-*-*-*-*")) + '(font . "-*-Source Code Pro-*-*-*-*-*-110-*-*-*-*-*")) (add-to-list 'default-frame-alist '(cursor-color . "green")) (add-to-list 'default-frame-alist '(foreground-color . "grey")) (add-to-list 'default-frame-alist '(background-color . "black")) @@ -134,8 +155,6 @@ '(define-auto-insert '("\\.\\(CC?\\|cc\\|cxx\\|cpp\\|c++\\)\\'" . "C++ source") '(nil - "#include \"common.hh\"" \n - \n (let ((base (file-name-sans-extension buffer-file-name))) (cond ((file-exists-p @@ -192,12 +211,21 @@ '(define-auto-insert '("\\.\\(java\\)\\'" . "Java source") '((file-name-base buffer-file-name) - "package " (mapconcat 'identity (member "com" (split-string (file-name-directory buffer-file-name) "/" t)) ".") ";" \n + "package " (mapconcat 'identity (member "org" (split-string (file-name-directory buffer-file-name) "/" t)) ".") ";" \n \n "class " str " {" \n - _ \n - str "() {" ?\n - " " "}" ?\n ;; > should work here but it doesn't + str "() {" \n + > _ ?\n + " }" ?\n + "}" \n))) +(eval-after-load 'autoinsert + '(define-auto-insert + '("\\.\\(kt\\)\\'" . "Kotlin source") + '((file-name-base buffer-file-name) + "package " (mapconcat 'identity (member "org" (split-string (file-name-directory buffer-file-name) "/" t)) ".") \n + \n + "class " str "() {" \n + > _ ?\n "}" \n))) (auto-insert-mode t) ;; don't ask before using auto-insert @@ -210,18 +238,88 @@ ;; keys (global-set-key (kbd "C-c o") 'ff-find-other-file) (global-set-key [?\C-x ?\t] 'toggle-selected-frame-width) +(define-key java-mode-map (kbd "M-I") 'java-imports-add-import-dwim) + +;; java-imports +(require 'java-imports) +(require 's) + +(defun jk-get-package-prefix (full-name) + "Return the first part of FULL-NAME, ie `android.' from `android.os.Bundle'. + +If there is no first part, full-name is returned in full." + (let ((match (s-match "[^.]*\\\." full-name))) + (if match + (car match) + full-name))) + + +(defun jk-package-prefix< (prefix1 prefix2) + "Return non-nil if PREFIX1 should be sorted before PREFIX2." + (if (s-starts-with? "java." prefix1) + (if (s-starts-with? "java." prefix2) + (string< prefix1 prefix2) + nil) + (if (s-starts-with? "java." prefix2) + t + (string< prefix1 prefix2)))) + + +(defun jk-find-place-sorted-blocks (full-name class-name package) + "Finds the insertion place within one of the sorted import blocks. + +Follows a convention where imports are separated in sorted blocks based +on first identifier in package name (com in one group, java in another) +ordered alphabetically with the exception of java that is always last." + + (let ((prefix (jk-get-package-prefix full-name))) + ;; Find group with same prefix if any + (while (or (and (java-imports-import-for-line) + (jk-package-prefix< (jk-get-package-prefix + (java-imports-import-for-line)) + prefix)) + (s-blank? (string-trim (thing-at-point 'line)))) + (forward-line 1)) + + (cond + ((and (java-imports-import-for-line) + (string= prefix (jk-get-package-prefix + (java-imports-import-for-line)))) + ;; insert into existing group + (while (and (java-imports-import-for-line) + (string< (java-imports-import-for-line) full-name)) + (forward-line 1)) + (open-line 1)) + (t + ;; create new group, adding separating blank line + (open-line 2))))) + +(setq java-imports-find-block-function 'jk-find-place-sorted-blocks) +(add-hook 'java-mode-hook 'java-imports-scan-file) -(require 'find-file-in-repository) (require 'ido) (require 'ido-vertical-mode) -(global-set-key (kbd "C-x f") 'find-file-in-repository) (ido-mode) (ido-vertical-mode) (setq ido-vertical-define-keys 'C-n-C-p-up-and-down) +(setq ido-vertical-pad-list nil) +;; stop ido from switchig to another frame where the same buffer is already open +(setq ido-default-buffer-method 'selected-window) + +;; glsl +(autoload 'glsl-mode "glsl-mode" nil t) +(add-to-list 'auto-mode-alist '("\\.glsl\\'" . glsl-mode)) +(add-to-list 'auto-mode-alist '("\\.vert\\'" . glsl-mode)) +(add-to-list 'auto-mode-alist '("\\.frag\\'" . glsl-mode)) +(add-to-list 'auto-mode-alist '("\\.geom\\'" . glsl-mode)) ;; flycheck (require 'flycheck) +(require 'flycheck-clangcheck) (global-flycheck-mode) +(setq flycheck-check-syntax-automatically '(save new-line)) +(setq flycheck-python-pylint-executable "/usr/bin/python3")' +(setq flycheck-clangcheck-analyze t) ;; replace ch alias fro grep with cchh alias, ie if starting with a ".h" file ;; you might still want to search in cc files @@ -248,85 +346,22 @@ '("common c" (c-basic-offset . 2))) -(defun get-base-dir (path needle) - "Get base directory for PATH using NEEDLE to cut." - (let ((parts (split-string path "/" t))) - (let ((index (cl-position needle parts :from-end t :test 'equal))) - (if index - (concat "/" (mapconcat 'identity (seq-take parts (+ index 1)) "/")) - path)))) - (make-variable-buffer-local 'flycheck-clang-definitions) (make-variable-buffer-local 'flycheck-clang-include-path) (make-variable-buffer-local 'flycheck-clang-language-standard) -(make-variable-buffer-local 'flycheck-clang-warnings) + +;; (setq flycheck-clang-language-standard "c++17" +;; flycheck-clang-definitions '("HAVE_CONFIG_H") +;; flycheck-clang-include-path +;; '("../include" "../src" "../build" "/usr/include/taglib" "/usr/include/cairo")) + +(require 'google-c-style) (add-hook 'c++-mode-hook (lambda() - (setq flycheck-clang-language-standard "c++14" - flycheck-clang-definitions '("HAVE_CONFIG_H") - flycheck-clang-include-path - '("../src" "../build")) - (c-set-style "default c++") - (when (and buffer-file-name - (string-match "/source/monmon/" buffer-file-name)) - (setq flycheck-clang-include-path - '("../src" "../build" - "/usr/include/cairo" - "/usr/include/pango-1.0" - "/usr/include/pixman-1" - "/usr/include/freetype2" - "/usr/include/libpng16" - "/usr/include/harfbuzz" - "/usr/include/glib-2.0" - "/usr/lib/glib-2.0/include" - "/usr/lib/icecream/include"))) - (when (and buffer-file-name - (string-match "/source/sawmill-0.5/" buffer-file-name)) - (setq flycheck-clang-include-path - '("../src" "../build" - "/usr/include/librsvg-2.0" - "/usr/include/gdk-pixbuf-2.0" - "/usr/include/cairo" - "/usr/include/pixman-1" - "/usr/include/freetype2" - "/usr/include/libpng16" - "/usr/include/harfbuzz" - "/usr/include/glib-2.0" - "/usr/lib/glib-2.0/include" - "../subprojects/googletest-release-1.8.0/googletest/include" - "../subprojects/googletest-release-1.8.0/googlemock/include" - ))) - ;; Chromium hook - (when (and buffer-file-name - (string-match "/chromium/src/" buffer-file-name)) - (let ((base (get-base-dir (file-name-directory buffer-file-name) "src"))) - (make-local-variable 'flycheck-clang-language-standard) - (make-local-variable 'flycheck-clang-include-path) - (setq flycheck-clang-language-standard "c++14" - flycheck-clang-definitions (list "OS_ANDROID") - flycheck-clang-warnings (list "no-unused-parameter") - flycheck-clang-include-path (list base - (concat base "/out_gradle/BetaArm7Debug/gen") - (concat base "/out_gradle/BetaArm7Release/gen")))) - (require 'google-c-style) - (c-add-style "Google" google-c-style t)) - ;; ofa hook - (when (and buffer-file-name - (string-match "/mobile/mobile/" buffer-file-name)) - (let ((base (get-base-dir (file-name-directory buffer-file-name) "mobile"))) - (make-local-variable 'flycheck-clang-language-standard) - (make-local-variable 'flycheck-clang-definitions) - (make-local-variable 'flycheck-clang-include-path) - (setq flycheck-clang-language-standard "c++14" - flycheck-clang-definitions (list "OS_ANDROID") - flycheck-clang-warnings (list "no-unused-parameter") - flycheck-clang-include-path (list base (concat base "/../../chromium/src") - (concat base "/../../chromium/src/third_party/re2/src") - (concat base "/../../chromium/src/out_gradle/BetaArm7Debug/gen") - (concat base "/../../chromium/src/out_gradle/BetaArm7Release/gen")))) - (require 'google-c-style) - (c-add-style "Google" google-c-style t)))) + (flycheck-select-checker 'c/c++-clangcheck) + (google-set-c-style) + (setq c-file-style "Google"))) ;; Opera Java hook (add-hook 'java-mode-hook @@ -343,7 +378,7 @@ flycheck-android-java-checkstyle-properties "checkstyle.properties" flycheck-android-java-variant - "devArm7Debug" + "devX86Debug" flycheck-android-java-skip-gen t) (require 'google-c-style) (google-set-c-style) @@ -355,3 +390,22 @@ (setq c-basic-offset 4)))) ;;; +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(package-selected-packages + '(kotlin-mode meson-mode groovy-mode gradle-mode flycheck ido-vertical-mode glsl-mode java-imports flycheck-android-experimental)) + '(safe-local-variable-values + '((eval let + ((project-path + (locate-dominating-file default-directory ".dir-locals.el"))) + (setq-local flycheck-clangcheck-build-path + (concat project-path "build")))))) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + ) |
