All Projects → liblit → demangle-mode

liblit / demangle-mode

Licence: GPL-3.0 license
Emacs minor mode that automatically demangles C++, D, and Rust symbols

Programming Languages

emacs lisp
2029 projects

Projects that are alternatives of or similar to demangle-mode

Writegood Mode
Minor mode for Emacs to improve English writing
Stars: ✭ 369 (+1950%)
Mutual labels:  emacs-mode
Subed
Subtitle editor for Emacs
Stars: ✭ 77 (+327.78%)
Mutual labels:  emacs-mode
Live Py Plugin
Live coding in Python with PyCharm, Emacs, Sublime Text, or even a browser
Stars: ✭ 222 (+1133.33%)
Mutual labels:  emacs-mode
Nyan Mode
Nyan Cat for Emacs! Nyanyanyanyanyanyanyanyanyan!
Stars: ✭ 590 (+3177.78%)
Mutual labels:  emacs-mode
Webpaste.el
webpaste.el can paste whole buffers or parts of buffers to several pastebin-like services and supports failover if one service fails.
Stars: ✭ 67 (+272.22%)
Mutual labels:  emacs-mode
Emacs Solidity
The official solidity-mode for EMACS
Stars: ✭ 120 (+566.67%)
Mutual labels:  emacs-mode
pdfgrep
PDFGrep is a GNU/Emacs module providing grep comparable facilities but for PDF files
Stars: ✭ 24 (+33.33%)
Mutual labels:  emacs-mode
groovy-emacs-modes
A groovy major mode, grails minor mode, and a groovy inferior mode.
Stars: ✭ 76 (+322.22%)
Mutual labels:  emacs-mode
Jq Mode
Emacs major mode for editing jq queries.
Stars: ✭ 70 (+288.89%)
Mutual labels:  emacs-mode
Emacs Fsharp Mode
F# Emacs mode
Stars: ✭ 160 (+788.89%)
Mutual labels:  emacs-mode
Clj Refactor.el
A collection of Clojure refactoring functions for Emacs
Stars: ✭ 694 (+3755.56%)
Mutual labels:  emacs-mode
Fingers.el
Modal editing minor mode for Emacs
Stars: ✭ 51 (+183.33%)
Mutual labels:  emacs-mode
Psc Ide Emacs
Emacs integration for PureScript's psc-ide tool.
Stars: ✭ 130 (+622.22%)
Mutual labels:  emacs-mode
Deft
Deft for Emacs
Stars: ✭ 521 (+2794.44%)
Mutual labels:  emacs-mode
Zoom
Fixed and automatic balanced window layout for Emacs
Stars: ✭ 252 (+1300%)
Mutual labels:  emacs-mode
Swift Mode
Emacs support for Apple's Swift programming language.
Stars: ✭ 308 (+1611.11%)
Mutual labels:  emacs-mode
Graphql Mode
An Emacs mode for GraphQL
Stars: ✭ 120 (+566.67%)
Mutual labels:  emacs-mode
list-environment.el
A tabulated process environment editor
Stars: ✭ 13 (-27.78%)
Mutual labels:  emacs-mode
tla-tools
TLA+ tools for Emacs
Stars: ✭ 27 (+50%)
Mutual labels:  emacs-mode
Org Msg
OrgMsg is a GNU/Emacs global minor mode mixing up Org mode and Message mode to compose and reply to emails in a Outlook HTML friendly style.
Stars: ✭ 153 (+750%)
Mutual labels:  emacs-mode

Demangle Mode

demangle-mode is an Emacs minor mode that automatically demangles C++, D, and Rust symbols. For example, in this mode:

  • the mangled C++ symbol _ZNSaIcED2Ev displays as std::allocator<char>::~allocator()

  • the mangled C++ symbol _GLOBAL__I_abc displays as global constructors keyed to abc

  • the mangled D symbol _D4test3fooAa displays as test.foo

  • the mangled Rust symbol _RNvNtNtCs1234_7mycrate3foo3bar3baz displays as mycrate::foo::bar::baz

How to Use

Quick Start

Install demangle-mode from the fantastic MELPA repository: MELPA, MELPA Stable. Or save demangle-mode.el somewhere in your Emacs load-path, then use M-x load-library RET demangle-mode RET to load the package.

Now use M-x demangle-mode to toggle demangling on or off in any buffer. Turn on font-lock-mode as well: demangle-mode uses this to stay in sync as buffer contents change.

Advanced Usage

If you did not install from the MELPA repository, add (autoload 'demangle-mode "demangle-mode" nil t) to your Emacs init file to load demangle-mode whenever you start Emacs.

If you always want demangling on in certain major modes, add demangle-mode to the appropriate major-mode hook, such as:

;; demangle symbols in LLVM bitcode
(add-hook 'llvm-mode-hook #'demangle-mode)

;; demangle symbols in linker error messages
(add-hook 'compilation-minor-mode-hook 'demangle-mode)

File and directory variables allow selective activation. For example, -*- eval: (demangle-mode) -*- anywhere on the first line of a file will turn on demangle-mode for that file only. To activate demangling for all LLVM assembly files in a specific directory, save the following text as .dir-locals.el in that same directory:

((llvm-mode
  (eval . (demangle-mode))))

Customization

Explore the demangle customization group for configurable options that affect this mode’s behavior: M-x customize-group RET demangle RET. You can choose between two styles of showing mangled/demangled symbols:

  • show the demangled symbol (read-only) on screen, with the original mangled symbol available as a help message or tooltip; or

  • show the mangled symbol on screen, with the demangled symbol available as a help message or tooltip.

Customization changes the initial style. A mode-specific menu allows switching between these styles when demangle-mode is on.

Additionally, you can customize the display face (font, color, underline, etc.) used for highlighting mangled and demangled symbols. The default highlighting face uses a thin gray box or wavy gray underline, depending on the output terminal’s capabilities.

Finally, you can change the set of languages that used mangled symbols. For example, you can add new mangled symbol patterns or change the external commands used to demangle them.

Background and Motivation

Name mangling is “a way of encoding additional information in the name of a function, structure, class or another datatype in order to pass more semantic information from the compilers to linkers.” For example, a C++ function named print taking a single int parameter might mangle to _Z5printi. A different print function taking two chars might mangle to _Z5printcc. This lets linkers and other tools distinguish the two functions.

Most programmer-facing tools demangle symbols back to their human-readable forms when producing output. Sometimes, though, we must work with “raw” text containing mangled, hard-to-read symbols. For example, LLVM assembly source from the Clang C++ compiler contains many raw, mangled symbols. It can be useful to demangle these in-place to make such files easier to read and understand. demangle-mode scratches that itch.

Compatibility Notes

demangle-mode uses font-lock-mode to recognize and change the display style of mangled symbols. If you want demangle-mode on in some buffer, you should usually turn on font-lock-mode as well. If you use demangle-mode without font-lock-mode, demangling happens only when explicitly requested (e.g., via M-x font-lock-fontify-buffer).

demangle-mode sets the help-echo and display text properties on mangled symbols. This could interfere with other packages or user actions that set these properties.

demangle-mode recognizes the popular Itanium ABI mangling scheme plus a few Linux/GCC extensions. Adding other mangled forms would be easy, if needed.

Mangled C++ and D symbols may optionally begin with an extra leading underscore, as some platforms prefix all symbols in this manner. Both _Z5printi and __Z5printi demangle identically to print(int), regardless of the host platform’s prefixing conventions.

C++ and D demangling uses the c++filt command. On GNU systems, this is part of binutils. If you need demangle-mode at all, you probably have binutils installed already.

Rust demangling uses the rustfilt command. If you need Rust demangling, then install rustfilt using your native package manager or using cargo as suggested here.

Known Issues and Design Limitations

The standard search commands are unaware of demangled symbol text. If _ZNSaIcED2Ev is being displayed as std::allocator<char>::~allocator(), incremental search and related commands will find this text as a match for SaI but not for ::.

When showing the demangled version of a symbol using a boxed face, the right edge of the box is missing in Emacs 24.3 and earlier. This was a known bug; the fix appears in Emacs 24.4 and later.

The faces used for mangled and demangled symbols are identical to each other, and picked somewhat arbitrarily. I welcome suggestions for nicer ways to mark such symbols or distinguish the mangled and demangled variants.

Building atop font-lock-mode simplifies keeping demangled symbols current as buffer contents change. However, this may surprise a user who turns on demangle-mode without font-lock-mode, then sees nothing happen.

Running an external demangler command once per symbol is too slow. Instead, we demangle in asynchronous background processes. This boosts performance but complicates the implementation. Demangling directly within Emacs would be clean and fast. Unfortunately, I know of no pure Emacs Lisp implementation of name demangling and do not wish to create one myself. Demanglers as C libraries do exist, but Emacs offers no in-process way to call into such a library.

Project Status at a Glance

Continuous Integration General Info Current Versions
Build Status Coverage Status License GPLv3 Motivation MELPA MELPA Stable
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].