Additional commands for scad-mode that rearrange the preview camera to display different standard views (top, bottom, left, right, front, and back), perform screen-aligned camera translations, and provide a transient menu and utility commands for working with SCAD projects (export, import, find/rename symbols, unused-variable checks, Flymake integration, and saving preview settings).
| Name | Version |
|---|---|
| Emacs | 29.1 |
scad-mode | 96.0 |
(use-package scad-extra
:straight (scad-extra
:repo "KarimAziev/scad-extra"
:type git
:host github
:flavor nil)
:hook ((scad-mode . scad-extra-reload-preview-mode)
(scad-mode . scad-extra-enable-flymake-check-unused-vars))
:bind ((:package scad-mode
:map scad-mode-map
("C-c C-e" . scad-extra-export)
([remap comment-dwim] . scad-extra-comment-dwim)
("C-M-r" . scad-extra-rename-symbol)
("C-c TAB" . scad-extra-import-project-file))
(:package scad-mode
:map scad-preview-mode-map
("?" . scad-extra-menu)
("f" . scad-extra-front-view)
("t" . scad-extra-top-view)
("l" . scad-extra-left-view)
("r" . scad-extra-right-view)
("b" . scad-extra-back-view)
("d" . scad-extra-bottom-view)
("<left>" . scad-preview-rotate-z+)
("<right>" . scad-preview-rotate-z-)
("<up>" . scad-preview-rotate-x+)
("<down>" . scad-preview-rotate-x-)
("M-<left>" . scad-extra-translate-left)
("M-<right>" . scad-extra-translate-right)
("M-<up>" . scad-extra-translate-up)
("M-<down>" . scad-extra-translate-down))))Download the source code and put it wherever you like, e.g. into ~/.emacs.d/scad-extra/
git clone https://github.com/KarimAziev/scad-extra.git ~/.emacs.d/scad-extra/Add the downloaded directory to the load path:
(add-to-list 'load-path "~/.emacs.d/scad-extra/")
(require 'scad-extra)This package provides two groups of functionality:
- Utilities for
scad-modebuffers (project import/export, find/rename, unused-variable analysis, Flymake integration, comment helpers). - Extra preview controls for
scad-preview-mode(view presets, translations, transient menu, save/restore preview-related variables). - Functions intended to be used as advice for specific
scad-modefunctions.
Invoke scad-extra-menu in scad-preview-mode for a grouped UI:
- Translate group: Up/Down/Left/Right/Forward/Backward (transient keys)
- Rotate group: Top/Bottom/Left/Right/Front/Back (transient keys)
- View Options: toggles for axes, crosshairs, edges, scales, wireframe (displayed as live toggles)
- Save group: change/save theme, projection, view or save changed preview variables
The transient UI also supports quick theme switching and resetting the preview.
scad-extra-top-viewRender the preview from a top (bird’s-eye) orientation.scad-extra-bottom-viewRender the preview from a bottom orientation.scad-extra-front-viewRender the preview from a front orientation.scad-extra-back-viewRender the preview from a back orientation.scad-extra-left-viewRender the preview from a left-side orientation.scad-extra-right-viewRender the preview from a right-side orientation.
Note
scad-extra-allow-reverse controls whether calling a view command when the camera is already in that view toggles to the opposite view (e.g. top <-> bottom).
Screen-aligned translations move the preview camera according to the onscreen directions (left/right/up/down) determined by the current preview camera orientation.
Tip
All translation commands accept an optional prefix argument to adjust the movement distance. If no prefix argument is supplied, the value of the custom variable scad-extra-translation-step is used.
scad-extra-translate-leftTranslate the preview camera to the left (screen-aligned) by the current step.scad-extra-translate-rightTranslate the preview camera to the right (screen-aligned) by the current step.scad-extra-translate-upTranslate the preview camera upward (toward the top of the screen) by the current step.scad-extra-translate-downTranslate the preview camera downward (toward the bottom of the screen) by the current step.scad-extra-translate-forwardTranslate the preview camera forward along the view direction by the current step.scad-extra-translate-backwardTranslate the preview camera backward along the view direction by the current step.
scad-extra-exportWrapper around scad-export that offers a customizable default directory (controlled byscad-extra-default-export-directory). Useful to export STLs into project-local directories (for example a project “stl/” directory).scad-extra-save-variablesSave modified preview-related customization variables listed inscad-extra-saveable-variables. Useful to persist camera/preview settings.scad-extra-import-project-fileInsert a “use” directive for a project file (with completion). With a prefix argument, inserts an “include” directive instead. The function tries to annotate already-imported files in the completion UI.scad-extra-comment-dwimEnhanced comment-dwim that supports different styles (configured via scad-extra-comment-dwim-default-style). With a prefix argument you can request alternate block-style comments.scad-extra-rename-symbolRename all occurrences of a symbol across project files (scans project files and rewrites occurrences not in comments/strings). Use with care - it performs textual replacements constrained to symbol-word boundaries.scad-extra-find-unused-variables-in-fileFind unused top-level parameters/variables and module-local unused variables in a single SCAD file. Produces a tabulated report buffer showing occurrences and allows jumping to the locations.scad-extra-find-unused-variables-in-projectRun the unused-variable analysis across the whole project and show a consolidated tabulated report.scad-extra-enable-flymake-check-unused-varsAdd a Flymake backend that highlights unused module parameters and variables within the current buffer (enables flymake-mode if needed).scad-extra-disable-flymake-check-unused-varsRemove the Flymake backend for unused variables (and disable flymake-mode if there are no other Flymake diagnostics).
scad-extra-reload-preview-mode(minor mode) When enabled in ascad-modebuffer, saving that buffer triggers a refresh of visible scad-preview buffers of files that import the saved file (via include/use). This is helpful when working with split buffers where one file defines parameters and another file imports them - saving the parameter file immediate re-renders dependent previews.
scad-extra-flymake and scad-extra-preview-render are intended to be used as overrides for scad-flymake and scad--preview-render. Both expand relative paths of imported files to absolute filenames in the temporary .scad files so imports and includes resolve correctly. For example:
atm_fuse_specs = import("power_lid_side_wall_atm_fuse_specs.json");Usage:
(advice-add 'scad-flymake :override #'scad-extra-flymake)
(advice-add 'scad--preview-render :override #'scad-extra-preview-render)