Skip to content

KarimAziev/scad-extra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

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).

Table of Contents

Requirements

NameVersion
Emacs29.1
scad-mode96.0

Installation

With use-package and straight.el

(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))))

Manual installation

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)

Usage

This package provides two groups of functionality:

  • Utilities for scad-mode buffers (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-mode functions.

Preview mode

Transient Menu

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.

View Commands

  • scad-extra-top-view Render the preview from a top (bird’s-eye) orientation.
  • scad-extra-bottom-view Render the preview from a bottom orientation.
  • scad-extra-front-view Render the preview from a front orientation.
  • scad-extra-back-view Render the preview from a back orientation.
  • scad-extra-left-view Render the preview from a left-side orientation.
  • scad-extra-right-view Render 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).

Translation Commands

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-left Translate the preview camera to the left (screen-aligned) by the current step.
  • scad-extra-translate-right Translate the preview camera to the right (screen-aligned) by the current step.
  • scad-extra-translate-up Translate the preview camera upward (toward the top of the screen) by the current step.
  • scad-extra-translate-down Translate the preview camera downward (toward the bottom of the screen) by the current step.
  • scad-extra-translate-forward Translate the preview camera forward along the view direction by the current step.
  • scad-extra-translate-backward Translate the preview camera backward along the view direction by the current step.

Other Commands

  • scad-extra-export Wrapper around scad-export that offers a customizable default directory (controlled by scad-extra-default-export-directory). Useful to export STLs into project-local directories (for example a project “stl/” directory).
  • scad-extra-save-variables Save modified preview-related customization variables listed in scad-extra-saveable-variables. Useful to persist camera/preview settings.
  • scad-extra-import-project-file Insert 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-dwim Enhanced 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-symbol Rename 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-file Find 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-project Run the unused-variable analysis across the whole project and show a consolidated tabulated report.
  • scad-extra-enable-flymake-check-unused-vars Add 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-vars Remove the Flymake backend for unused variables (and disable flymake-mode if there are no other Flymake diagnostics).

Reload Preview Mode

  • scad-extra-reload-preview-mode (minor mode) When enabled in a scad-mode buffer, 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.

Advice functions

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)

About

Additional commands for scad-mode.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors