From 54fbf6576cf2dd94ef5af332a6075723a9dfa8b3 Mon Sep 17 00:00:00 2001 From: Blendoit Date: Tue, 28 Jul 2020 22:01:57 -0700 Subject: Tabs, menu entry suppression, and small section reorg. --- blendoit/init-blendoit.org | 340 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 317 insertions(+), 23 deletions(-) (limited to 'blendoit/init-blendoit.org') diff --git a/blendoit/init-blendoit.org b/blendoit/init-blendoit.org index 28962e2..2a78126 100644 --- a/blendoit/init-blendoit.org +++ b/blendoit/init-blendoit.org @@ -129,6 +129,7 @@ mode. (global-set-key (kbd "C-b") 'ibuffer-sidebar-toggle-sidebar) (global-set-key (kbd "C-o") 'menu-find-file-existing) (global-set-key (kbd "C-r") 'counsel-recentf) + (global-set-key (kbd "C-n") 'make-frame) #+END_SRC The following bindings lead to more natural exit behaviors. @@ -502,17 +503,6 @@ Oí, Jason! :config (pdf-loader-install)) #+END_SRC -** rainbow - -This highlights hexadecimal numbers which look like colors, in that same color. - -#+BEGIN_SRC emacs-lisp -(use-package rainbow-mode - :ensure t - :init - (add-hook 'prog-mode-hook 'rainbow-mode)) -#+END_SRC - ** Dashboard We replace the standard welcome screen with our own. @@ -528,6 +518,17 @@ We replace the standard welcome screen with our own. (setq dashboard-banner-logo-title "The editor for the 2nd millenium.")) #+END_SRC +** rainbow + +This highlights hexadecimal numbers which look like colors, in that same color. + +#+BEGIN_SRC emacs-lisp +(use-package rainbow-mode + :ensure t + :init + (add-hook 'prog-mode-hook 'rainbow-mode)) +#+END_SRC + ** Projectile This enables us to better manage our =.git= projects. @@ -539,6 +540,20 @@ This enables us to better manage our =.git= projects. (setq projectile-completion-system 'ivy)) #+END_SRC +** Better parentheses + +#+BEGIN_SRC emacs-lisp +(show-paren-mode 1) + + (use-package smartparens + :config + (add-hook 'prog-mode-hook #'smartparens-mode)) + + (use-package rainbow-delimiters + :config + (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)) +#+END_SRC + * Cosmetics ** Faces & cursors @@ -627,6 +642,100 @@ Disable minibuffer scroll bar. ; (set-window-scroll-bars (ibuffer-sidebar-window) nil nil) #+END_SRC +** Clean up menus + +We reduce the burden on the user by reducing total amount of entries in GUI +menus. + +*** File + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-file-menu [print-buffer] nil) +(define-key menu-bar-file-menu [print-region] nil) +(define-key menu-bar-file-menu [ps-print-buffer-faces] nil) +(define-key menu-bar-file-menu [ps-print-region-faces] nil) +(define-key menu-bar-file-menu [ps-print-buffer] nil) +(define-key menu-bar-file-menu [ps-print-region] nil) +(define-key menu-bar-file-menu [split-window-below] nil) +(define-key menu-bar-file-menu [split-window-right] nil) +(define-key menu-bar-file-menu [dired] nil) +#+END_SRC + +*** Edit + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +#+END_SRC + +*** Options + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +#+END_SRC + +*** Buffers + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +#+END_SRC + +*** Tools + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +#+END_SRC + +*** Org + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +#+END_SRC + +*** Tbl + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +#+END_SRC + +*** Text + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +#+END_SRC + +*** Projectile + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +#+END_SRC + +*** Help + +#+BEGIN_SRC emacs-lisp +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +(define-key menu-bar-file-menu [dired] nil) +(define-key menu-bar-help-menu [emacs-psychotherapist] nil) +#+END_SRC + +** Coding standards + This is just a better default. #+BEGIN_SRC emacs-lisp @@ -634,6 +743,203 @@ This is just a better default. c-basic-offset 4) #+END_SRC +** Tabs + +#+BEGIN_SRC emacs-lisp +(use-package tabbar) +#+END_SRC + +Thank you +https://andreyorst.gitlab.io/posts/2020-05-10-making-emacs-tabs-look-like-in-atom/ + +#+BEGIN_SRC emacs-lisp +(when (and window-system + (not (version< emacs-version "27"))) + (use-package tab-line + :hook (after-init . global-tab-line-mode) + :config + (defun tab-line-close-tab (&optional e) + "Close the selected tab. + +If tab is presented in another window, close the tab by using +`bury-buffer` function. If tab is unique to all existing +windows, kill the buffer with `kill-buffer` function. Lastly, if +no tabs left in the window, it is deleted with `delete-window` +function." + (interactive "e") + (let* ((posnp (event-start e)) + (window (posn-window posnp)) + (buffer (get-pos-property 1 'tab (car (posn-string posnp))))) + (with-selected-window window + (let ((tab-list (tab-line-tabs-window-buffers)) + (buffer-list (flatten-list + (seq-reduce (lambda (list window) + (select-window window t) + (cons (tab-line-tabs-window-buffers) list)) + (window-list) nil)))) + (select-window window) + (if (> (seq-count (lambda (b) (eq b buffer)) buffer-list) 1) + (progn + (if (eq buffer (current-buffer)) + (bury-buffer) + (set-window-prev-buffers window (assq-delete-all buffer (window-prev-buffers))) + (set-window-next-buffers window (delq buffer (window-next-buffers)))) + (unless (cdr tab-list) + (ignore-errors (delete-window window)))) + (and (kill-buffer buffer) + (unless (cdr tab-list) + (ignore-errors (delete-window window))))))))) + + + (defcustom tab-line-tab-min-width 10 + "Minimum width of a tab in characters." + :type 'integer + :group 'tab-line) + + + (defcustom tab-line-tab-max-width 30 + "Maximum width of a tab in characters." + :type 'integer + :group 'tab-line) + + (defcustom tab-line-ellipsis-string "…" + "String for indicating truncated names" + :type 'string + :group 'tab-line) + + (defun aorst/tab-line--tab-width (window-width tab-amount) + "Calculate width of single tab dividing WINDOW-WIDTH by TAB-AMOUNT." + (let* ((close-button-size + (if tab-line-close-button-show + (length (substring-no-properties tab-line-close-button)) 0)) + (tab-width (/ window-width tab-amount))) + (- (cond ((< window-width 0) + tab-line-tab-min-width) + ((>= tab-width tab-line-tab-max-width) + tab-line-tab-max-width) + ((< tab-width tab-line-tab-min-width) + tab-line-tab-min-width) + (t tab-width)) + close-button-size))) + + (defun aorst/tab-line--max-width (window) + "Calculate free width of the WINDOW. + +Free width means amount of space we can use to display tabs +without truncation." + (- (window-width window) + (length (substring-no-properties tab-line-left-button)) + (length (substring-no-properties tab-line-right-button)) + (if tab-line-new-button-show + (length (substring-no-properties tab-line-new-button)) + 0))) + + + (defun aorst/tab-line--make-pad (tab-width name-width) + "Generate padding string based on TAB-WIDTH and NAME-WIDTH." + (let* ((width (- tab-width name-width)) + (padding (/ (if (oddp width) (+ width 1) width) 2))) + (make-string padding ?\s))) + + + (defun aorst/tab-line-name-buffer (buffer &rest _buffers) + "Create name for tab with padding and truncation. + +If buffer name is shorter than `tab-line-tab-max-width' it gets +centered with spaces, otherwise it is truncated, to preserve +equal width for all tabs. This function also tries to fit as +many tabs in window as possible, so if there are no room for tabs +with maximum width, it calculates new width for each tab and +truncates text if needed. Minimal width can be set with +`tab-line-tab-min-width' variable." + (with-current-buffer buffer + (let* ((amount (length (tab-line-tabs-window-buffers))) + (width (aorst/tab-line--tab-width + (aorst/tab-line--max-width (get-buffer-window buffer)) + amount)) + (buffer (string-trim (buffer-name))) + (name-width (length buffer)) + (right-pad (if tab-line-close-button-show "" " ")) + (truncate-width (- width + (length tab-line-ellipsis-string) + (length right-pad)))) + (if (>= name-width truncate-width) + (concat " " (truncate-string-to-width buffer truncate-width) tab-line-ellipsis-string right-pad) + (let* ((padding (aorst/tab-line--make-pad width name-width)) + (tab-text (concat padding buffer)) + (text-width (length tab-text))) + (concat tab-text (make-string (- width text-width) ?\s))))))) + + + (setq tab-line-close-button-show t + tab-line-new-button-show nil + tab-line-separator "" + tab-line-tab-name-function #'aorst/tab-line-name-buffer + tab-line-right-button (propertize (if (char-displayable-p ?▶) " ▶ " " > ") + 'keymap tab-line-right-map + 'mouse-face 'tab-line-highlight + 'help-echo "Click to scroll right") + tab-line-left-button (propertize (if (char-displayable-p ?◀) " ◀ " " < ") + 'keymap tab-line-left-map + 'mouse-face 'tab-line-highlight + 'help-echo "Click to scroll left") + tab-line-close-button (propertize (if (char-displayable-p ?×) " × " " x ") + 'keymap tab-line-tab-close-map + 'mouse-face 'tab-line-close-highlight + 'help-echo "Click to close tab")) + + + (let ((bg (if (facep 'solaire-default-face) + (face-attribute 'solaire-default-face :background) + (face-attribute 'default :background))) + (fg (face-attribute 'default :foreground)) + (base (if (facep 'solaire-default-face) + (face-attribute 'default :background) + (face-attribute 'mode-line :background))) + (box-width (/ (line-pixel-height) 2))) + (when (and (color-defined-p bg) + (color-defined-p fg) + (color-defined-p base) + (numberp box-width)) + (set-face-attribute 'tab-line nil + :background base + :foreground fg + :height 1.0 + :inherit nil + :box (list :line-width -1 :color base)) + (set-face-attribute 'tab-line-tab nil + :foreground fg + :background bg + :weight 'normal + :inherit nil + :box (list :line-width box-width :color bg)) + (set-face-attribute 'tab-line-tab-inactive nil + :foreground fg + :background base + :weight 'normal + :inherit nil + :box (list :line-width box-width :color base)) + (set-face-attribute 'tab-line-tab-current nil + :foreground fg + :background bg + :weight 'normal + :inherit nil + :box (list :line-width box-width :color bg)))) + (setq tab-line-exclude-modes '()) + (dolist (mode '(ediff-mode + process-menu-mode + term-mode + vterm-mode)) + (add-to-list 'tab-line-exclude-modes mode)) + + (defun aorst/tab-line-drop-caches () + "Drops `tab-line' cache in every window." + (dolist (window (window-list)) + (set-window-parameter window 'tab-line-cache nil))) + + (add-hook 'window-configuration-change-hook #'aorst/tab-line-drop-caches))) +#+END_SRC + ** auto fill Automatically break lines longer than =fill-column=. @@ -651,18 +957,6 @@ Automatically break lines longer than =fill-column=. (run-at-time nil (* 5 60) 'recentf-save-list) #+END_SRC -** Better parentheses - -#+BEGIN_SRC emacs-lisp - (use-package smartparens - :config - (add-hook 'prog-mode-hook #'smartparens-mode)) - - (use-package rainbow-delimiters - :config - (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)) -#+END_SRC - * Profiling --- stop #+BEGIN_SRC emacs-lisp -- cgit v1.2.3