CrystalClear at 2025-07-17T18:21:07+00:00
The JavaScript event system enables loosely coupled functions but leads to tightly coupled data that must be passed around and often requires complex tracing to understand its origin. A client shouldn’t have data sent to them, just be made aware of when data is updated, and the one emitting the info shouldn’t have to know who is listening. The message and the data shouldn’t be associated. No coupling of it and passing through several parts like typical events. All that’s given is a message that something happened. The component is then responsible itself for gathering the data in ordinary ways, for example by calling the source module’s interface. This ensures we have only one way of gathering data, not as in event handlers where data comes from different places or at least from an interface perceived to be abstract as the system grows. All components are thus loosely coupled and made into well-defined, solid, independent units as much as possible.
➥ CrystalClear said:
Much software, when you open it, perhaps GDB if I remember the debugger, there is only one small main()
function calling the rest of the system, startup, etc. Similarly, I think of keeping init.lua
clean for my Neovim Lazy plugin. After all, its name doesn't bear any of our conceptual connotation and we are in the domain of lazy concept, we need to exit that domain and get to our own, so keep init
minimal.
[view] (1 reply)CrystalClear at 2025-07-14T08:24:16+00:00
Yes, establish your own conceptual domain. Draw clear boundaries between your system and the systems that are dependencies or of perconditions.
CrystalClear at 2025-07-14T08:17:11+00:00
Much software, when you open it, perhaps GDB if I remember the debugger, there is only one small main()
function calling the rest of the system, startup, etc. Similarly, I think of keeping init.lua
clean for my Neovim Lazy plugin. After all, its name doesn't bear any of our conceptual connotation and we are in the domain of lazy concept, we need to exit that domain and get to our own, so keep init
minimal.
CrystalClear at 2025-07-13T19:12:42+00:00
Installing Prettier globally
Note: Working on solution to get prettier with prettier-php plugin to run in nvim, but turns out better use prettier for css/js and php-cs-fixer for php, and avoid mixing as much as possible. Seems like my prettier-php plugin wouldn't run globally, or was it all of prettier, but then installing prettier globally with pacman still makes it accessible globally. It works now, and I do not remember how I got into this mess.
---
Recent changes, to V3, disables global access and I do not want to install it locally in my 500 projects. And I do not use plugin managers but rely on bare bone integration into nvim.
From Prettier's "Editor Integration" manual:
> Note! It’s important to install Prettier locally in every project, so each project gets the correct Prettier version.
Error
>[error] No parser could be inferred for file "/..."
So in project local dir: npm install --save-dev --save-exact prettier
and npm install --save-dev prettier @prettier/plugin-php
.
Solution
1, Install it in a dedicated directory.
2, Create script 1
(submitted below).
3. Use that script in place of the Pretty command.
Script 1
Make it have same interface as clang-format for example, receive piped input and return formatted version to stdout, then integrate with nvim as with for example clang-format. We need to pass the filename to prettier too.
#!/bin/bash<br />
set -euo pipefail<br />
<br />
if [[ $# -lt 1 ]]; then<br />
echo "Usage: $0 <filename-for-context.php>" >&2<br />
exit 1<br />
fi<br />
<br />
FILENAME="$1"<br />
cd "/path/to/install/dir/prettier" || exit 1<br />
<br />
exec node_modules/.bin/prettier \<br />
--config .prettierrc \<br />
--stdin-filepath "$FILENAME"<br />
```<br />
<br />
<br />
<br />
### Example conform.lua<br />
<br />
Using _conform.nvim_ to load formatters, here is what I use (yes, currently inconsistency with _stop_after_first_):<br />
<br />
```<br />
return {<br />
"stevearc/conform.nvim",<br />
config = function()<br />
require("conform").setup({<br />
log_level = vim.log.levels.DEBUG,<br />
debug = true,<br />
formatters_by_ft = {<br />
lua = { "stylua" },<br />
sh = { "shfmt" },<br />
bash = { "shfmt" },<br />
javascript = { "prettier" },<br />
typescript = { "prettier" },<br />
html = { "prettier" },<br />
css = { "prettier" },<br />
json = { "prettier" },<br />
markdown = { "prettier" },<br />
yaml = { "prettier" },<br />
c = { "clang_format" },<br />
php = {<br />
<br />
"prettier_format",<br />
stop_after_first = true,<br />
},<br />
},<br />
formatters = {<br />
prettier_format = {<br />
command = "prettier-global",<br />
args = { "$FILENAME" },<br />
},<br />
clang_format = {<br />
command = "clang-format",<br />
args = {<br />
[[--style={<br />
BasedOnStyle: llvm,<br />
BreakBeforeBraces: Allman,<br />
AlignAfterOpenBracket: Align,<br />
AlignConsecutiveAssignments: true,<br />
AlignTrailingComments: true,<br />
IndentWidth: 6,<br />
SpacesInParentheses: true,<br />
SpacesInSquareBrackets: true<br />
}]],<br />
},<br />
},<br />
},<br />
})<br />
<br />
-- Add this block to enable format-on-save<br />
vim.api.nvim_create_autocmd("BufWritePre", {<br />
callback = function(args)<br />
require("conform").format({ bufnr = args.buf })<br />
end,<br />
})<br />
end,<br />
}<br />
➥ CrystalClear said:
npm root -g
is /usr/lib/node_modules, updated to: npm config set prefix /usr/local
, because prettier plugin is in /usr/lib/node_modules
.
[view] (1 reply)CrystalClear at 2025-07-13T14:13:00+00:00
reverted this, problem is Prettier plugin changed to no longer load modules globally.
CrystalClear at 2025-07-13T12:50:42+00:00
npm root -g
is /usr/lib/node_modules, updated to: npm config set prefix /usr/local
, because prettier plugin is in /usr/lib/node_modules
.