Files
emacs/lisp/my/my-view.el
2025-06-14 22:46:40 +02:00

170 lines
5.2 KiB
EmacsLisp

;;; my-view.el --- Personal library view -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(defun my-view-python ()
"Python IDE like view.
Language Server Support, Emacs built-in package `eglot'
Language Server Protocol, python package `python-lsp-server'
- install e.g. with: pip install \"python-lsp-server[all]\"
Syntax Checking, Emacs built-in package `flymake'
Four windows:
- left: file
- right
- top: help (`eldoc')
- middle: cross-references (`xref')
- bottom: python shell
"
(interactive)
(require 'python)
(setq eldoc-echo-area-prefer-doc-buffer t)
(setq eglot-sync-connect t)
(let ()
;; first make visiting file full and run eglot
(delete-other-windows)
(eglot-ensure)
;; split horizontal 0.6/0.4
;; (split-window-horizontally (truncate (* 0.6 (window-body-width))))
(split-window-horizontally)
(other-window 1)
;; (switch-to-buffer (concat "*eldoc*"))
(eldoc-display-in-buffer t nil)
(when (get-buffer (eldoc-doc-buffer))
(switch-to-buffer (eldoc-doc-buffer)))
;; ;; (other-window 1)
;; ;; (eldoc-doc-buffer 1)
;; ;; (window-resize nil (truncate (* 0.2 (window-body-width))) t nil nil)
;; split vertical xref and python shell
;; (other-window 1)
(split-window-vertically)
(other-window 1)
(split-window-vertically)
(switch-to-buffer (concat "*xref*"))
(other-window 1)
(switch-to-buffer (concat "*" python-shell-buffer-name "*"))
(run-python)
;; size
(other-window 1)
(balance-windows)
(window-resize nil (truncate (* 0.2 (window-body-width))) t nil nil)
)
)
;; python old using anaconda
;; (defun my-view-python ()
;; "Three windows.
;; On the right side a *Anaconda* buffer with optionally
;; `virtual-auto-fill-mode' active and a *Python* buffer."
;; (interactive)
;; (require 'python)
;; (unless (get-buffer (concat "*" python-shell-buffer-name "*"))
;; (run-python) ;; cursor is now inside the python buffer.
;; (other-window -1))
;; (delete-other-windows)
;; (split-window-horizontally (truncate (* 0.6 (window-body-width))))
;; (other-window 1)
;; (switch-to-buffer (concat "*" python-shell-buffer-name "*"))
;; (split-window-vertically) ;; both are python buffers now.
;; (switch-to-buffer "*Anaconda*")
;; (when (fboundp 'virtual-auto-fill-mode) (virtual-auto-fill-mode))
;; (other-window -1))
(defun my-view-elisp ()
"Two windows side-by-side.
On the right side a *Help* buffer with optionally
`virtual-auto-fill-mode' active."
(interactive)
(delete-other-windows)
(split-window-horizontally (truncate (* 0.6 (window-body-width))))
(other-window 1)
(switch-to-buffer "*Help*")
(other-window -1))
(defun my-view-shell ()
"Two windows side-by-side.
On the right side a *compilation* buffer.
Use `compile' with `sh <foo.sh -flag command>' to run the script."
;; TODO: rebind compile to C-c and auto fill sh with filename
;; TODO: rebind recompile to ??? to use last compile command
;; https://masteringemacs.org/article/compiling-running-scripts-emacs
;; TODO: for shell-script buffers:
;; ;;; Shut up compile saves
;; (setq compilation-ask-about-save nil)
;; ;;; Don't save *anything*
;; (setq compilation-save-buffers-predicate '(lambda () nil))
(interactive)
(delete-other-windows)
(split-window-horizontally (truncate (* 0.6 (window-body-width))))
(other-window 1)
(switch-to-buffer "*compilation*")
(other-window -1))
(defun my-view-org-pdf ()
"Two windows side-by-side.
On the right side a DocView buffer displaying the pdf."
(interactive)
(delete-other-windows)
(let ((bufnam (buffer-name))
(buffilnam buffer-file-name))
(split-window-horizontally)
(other-window 1)
;;(switch-to-buffer (concat (file-name-sans-extension bufnam) ".pdf"))
(find-file (concat (file-name-sans-extension buffilnam) ".pdf"))
(doc-view-fit-height-to-window)
(doc-view-fit-window-to-page)
(other-window -1)))
(defun my-view-gnuplot ()
"Three windows.
On the right side a *Shell* buffer with optionally
`virtual-auto-fill-mode' active and an Image mode buffer."
(interactive)
(save-excursion
(let (output-file-name) ;; get figure output name
(goto-char (point-min))
(when (re-search-forward "set output .*" nil t)
;; TODO: search text in between set output '...' then I do not
;; need to replace / remove part of the match string.
(setq output-file-name (match-string 0))
(setq output-file-name (string-replace "set output " "" output-file-name))
(setq output-file-name (substring output-file-name 1 -1)))
;;(message "%s" output-file-name)
(delete-other-windows)
(split-window-horizontally (truncate (* 0.6 (window-body-width))))
(other-window 1)
(if output-file-name
;;(switch-to-buffer output-file-name)
(find-file output-file-name)
;;(switch-to-buffer "*scratch*")
(switch-to-buffer " *image*"))
;;(when (fboundp 'virtual-auto-fill-mode) (virtual-auto-fill-mode))
(split-window-vertically) ;; both are shell buffers now.
(switch-to-buffer "*shell*")
(shell)
;;(when (fboundp 'virtual-auto-fill-mode) (virtual-auto-fill-mode))
(other-window -1))))
(provide 'my-view)
;;; my-view.el ends here