# Fg42 - Emacs Editor for advance users # # Copyright (c) 2010-2024 Sameer Rahmani # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 2. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . { pkgs, lib }: let isStrEmpty = s: (builtins.replaceStrings [ " " ] [ "" ] s) == ""; splitString = _sep: _s: builtins.filter (x: builtins.typeOf x == "string") (builtins.split _sep _s); in { elispStr , alwaysEnsure ? false }: let inherit (import ./elisp_reader.nix { inherit lib; }) fromElisp; readFunction = fromElisp; find = item: list: if list == [] then [] else if builtins.head list == item then list else find item (builtins.tail list); getKeywordValue = keyword: list: let keywordList = find keyword list; in if keywordList != [] then let keywordValue = builtins.tail keywordList; in if keywordValue != [] then builtins.head keywordValue else true else null; isDisabled = item: let disabledValue = getKeywordValue ":disabled" item; in if disabledValue == [] then false else if builtins.isBool disabledValue then disabledValue else if builtins.isString disabledValue then true else false; getName = item: let ensureValue = getKeywordValue ":ensure" item; usePackageName = builtins.head (builtins.tail item); in if builtins.isString ensureValue then if lib.hasPrefix ":" ensureValue then usePackageName else ensureValue else if ensureValue == true || (ensureValue == null && alwaysEnsure) then usePackageName else []; recurse = item: if builtins.isList item && item != [] then let packageManager = builtins.head item; in if builtins.elem packageManager [ "depends-on" ] then if !(isDisabled item) then [ packageManager (getName item) ] ++ map recurse item else [] else map recurse item else []; in lib.flatten (map recurse (readFunction elispStr))