Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Highlight in the bundle #73

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "hl/highlight"]
path = hl/highlight
url = https://gitlab.com/saalen/highlight.git
[submodule "hl/lua"]
path = hl/lua
url = https://github.com/lua/lua.git
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
addons:
homebrew:
packages:
- boost
language: objective-c
xcode_project: QLColorCode.xcodeproj
xcode_scheme: Travis
script: set -o pipefail && xcodebuild -project QLColorCode.xcodeproj -scheme Travis build | xcpretty
340 changes: 339 additions & 1 deletion QLColorCode.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
This is a Quick Look plug-in that renders source code with syntax highlighting,
using the [Highlight library](http://www.andre-simon.de).

To install Highlight, [download the library manually](http://www.andre-simon.de/zip/download.php), or use Homebrew `brew install highlight`

To install the plug-in, just drag it to `~/Library/QuickLook`.
You may need to create that folder if it doesn't already exist.

Alternative, if you use [Homebrew Cask](https://github.com/caskroom/homebrew-cask),
Alternatively, if you use [Homebrew Cask](https://github.com/caskroom/homebrew-cask),
install with `brew cask install qlcolorcode`.

Also available on MacPorts: `port install QLColorCode`.

To build the project, you must have Boost headers on your system in
`/opt/local/include` or `/usr/local/include`.

## Settings

If you want to configure `QLColorCode`, there are several `defaults` commands that could be useful:
Expand Down
11 changes: 11 additions & 0 deletions hl/apply-patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
cd "$DIR"
for i in lua highlight
do
pushd "$i"
git checkout . || true
patch -p1 < "../${i}.patch"
popd
done
1 change: 1 addition & 0 deletions hl/highlight
Submodule highlight added at e55d1f
24 changes: 24 additions & 0 deletions hl/highlight.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/src/makefile b/src/makefile
index 9d0a08e..0a7a833 100644
--- a/src/makefile
+++ b/src/makefile
@@ -43,8 +43,8 @@ ifeq (${LUA_TEST},1)
LUA_PKG_NAME=lua
endif

-LUA_CFLAGS=$(shell pkg-config --cflags ${LUA_PKG_NAME})
-LUA_LIBS=$(shell pkg-config --libs ${LUA_PKG_NAME})
+LUA_CFLAGS=-I../../lua -I../..
+LUA_LIBS=../../lua/liblua.a

# luajit lib
# LUA_LIBS=$(shell pkg-config --libs luajit)
@@ -75,7 +75,7 @@ LDFLAGS = -ldl
#LDFLAGS = ${LDFLAGS} -s
#LDFLAGS= -Wl,--as-needed

-CXX_COMPILE=${CXX} ${CFLAGS} -c -I ${INCLUDE_DIR} ${LUA_CFLAGS}
+CXX_COMPILE=${CXX} ${CFLAGS} -c -I /opt/local/include -I /usr/local/include -I ${INCLUDE_DIR} ${LUA_CFLAGS}

# Data directories (data dir, configuration file dir)
CXX_DIR=-DHL_DATA_DIR=\"${HL_DATA_DIR}\" -DHL_CONFIG_DIR=\"${HL_CONFIG_DIR}\"
1 change: 1 addition & 0 deletions hl/lua
Submodule lua added at 9d067a
9 changes: 9 additions & 0 deletions hl/lua.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// lua.hpp
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
17 changes: 17 additions & 0 deletions hl/lua.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/makefile b/makefile
index 9e537dcc..d275b809 100644
--- a/makefile
+++ b/makefile
@@ -60,9 +60,9 @@ LOCAL = $(TESTS) $(CWARNS)


# enable Linux goodies
-MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_LINUX -DLUA_USE_READLINE
-MYLDFLAGS= $(LOCAL) -Wl,-E
-MYLIBS= -ldl -lreadline
+MYCFLAGS= $(LOCAL) -std=c99
+MYLDFLAGS= $(LOCAL)
+MYLIBS= -ldl


CC= gcc
21 changes: 1 addition & 20 deletions src/Common.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,6 @@
NSMutableDictionary *env = [NSMutableDictionary dictionaryWithDictionary:
[[NSProcessInfo processInfo] environment]];

NSString *path = [env objectForKey: @"PATH"];
NSString *newPath = [path stringByAppendingString: @":/opt/local/bin:/usr/local/bin:/usr/local/sbin"];
[env setObject: newPath forKey: @"PATH"];

// Try to find highlight location
NSString *highlightPath = [[defaults persistentDomainForName:myDomain] valueForKey:@"pathHL"];
if (highlightPath == nil) {
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
NSData* data = runTask(@"which highlight", env, status);
highlightPath = [[[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease] stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
if (*status == 0 && [highlightPath hasPrefix: @"/"] && [highlightPath hasSuffix: @"highlight"]) { // i.e. highlightPath looks like the actual path
NSMutableDictionary *newDefaults = [NSMutableDictionary dictionaryWithObject:highlightPath forKey:@"pathHL"];
[newDefaults addEntriesFromDictionary: [defaults persistentDomainForName:myDomain]];
[userDefaults setPersistentDomain: newDefaults forName:myDomain];
[userDefaults synchronize];
}
[userDefaults release];
}

[env addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
#ifdef DEBUG
@"1", @"qlcc_debug",
Expand All @@ -103,7 +84,7 @@
@"edit-xcode", @"hlTheme",
// @"-lz -j 3 -t 4 --kw-case=capitalize ", @"extraHLFlags",
@"-t 4 ", @"extraHLFlags",
@"/opt/local/bin/highlight", @"pathHL",
[rsrcEsc stringByAppendingString:@"/highlight"], @"pathHL",
@"", @"maxFileSize",
@"UTF-8", @"textEncoding",
@"UTF-8", @"webkitTextEncoding", nil]];
Expand Down
6 changes: 3 additions & 3 deletions src/colorize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ go4it () {

debug "Generating the preview"
if [ "${thumb}" = "1" ]; then
${reader} | head -n 100 | head -c 20000 | ${cmd} ${cmdOpts} && exit 0
${reader} | head -n 100 | head -c 20000 | ${cmd} -D "${rsrcDir}" ${cmdOpts} && exit 0
elif [ -n "${maxFileSize}" ]; then
${reader} | head -c ${maxFileSize} | ${cmd} -T "${target}" ${cmdOpts} && exit 0
${reader} | head -c ${maxFileSize} | ${cmd} -D "${rsrcDir}" -T "${target}" ${cmdOpts} && exit 0
else
${reader} | ${cmd} -T "${target}" ${cmdOpts} && exit 0
${reader} | ${cmd} -D "${rsrcDir}" -T "${target}" ${cmdOpts} && exit 0
fi
}

Expand Down